Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Perl XAMPP DB Connect issue (Windows/Strawberry?)

by Polyglot (Chaplain)
on Jan 01, 2023 at 02:51 UTC ( [id://11149245] : note . print w/replies, xml ) Need Help??


in reply to Re: Perl XAMPP DB Connect issue (Windows/Strawberry?)
in thread Perl XAMPP DB Connect issue (Windows/Strawberry?)

My options are nearly exhausted at this point. I have made some discoveries, some good, some not.

I downloaded Strawberry Perl, which is supposed to have DBD::mysql and all that is necessary, and found it to apparently have the identical list of libraries that came with XAMPP. So that's the bad news--XAMPP is not working out of the box with what, by all accounts online, appears to be the best possible option for getting Perl going on Windows.

The good news is that I found the DBD::mysql library tucked into a directory where I would not have expected it. It was in "C:\xampp\perl\vendor\lib\auto\".

But more bad news is coming. The file is not compatible for some reason. An error message leading back to DynaLoader.pm appears saying "Can't load 'C:/xampp/perl/vendor/lib/auto/DBD/mysql/mysql.xs.dll' for module DBD::mysql: load_file: The specified module could not be found at C:/xampp/perl/lib/DynaLoader.pm line 193."

I tried a "hail Mary"-style push of the path for the DBD module to DynaLoader's "@dl_library_path" array...to no avail, of course.

It looks like this is where the whole project dies. Is there an easy way to inline some php to handle the DB connections that I cannot do with Perl?

I'd really hate to go back to having to run a linux VM on windows just to get perl to use a database--it takes a whopping amount of space to do it this way, not to mention the added layers of complexity with accessing it via the VM.

Blessings,

~Polyglot~

  • Comment on Re^2: Perl XAMPP DB Connect issue (Windows/Strawberry?)

Replies are listed 'Best First'.
Re^3: Perl XAMPP DB Connect issue (Windows/Strawberry?) - WSL Ubuntu
by eyepopslikeamosquito (Archbishop) on Jan 01, 2023 at 05:02 UTC
      If it were my computer, based on what little I know, I would have zero interest in downgrading to Windows 11. But it's not even mine.

      As for using 17 GB, and still without a DBI/DBD solution, that illustrates the issue. I think I'm in about 2 GB total right now: XAMPP takes about 700 MB, plus I've had to install MSYS2: 277 MB; 7-Zip: 6 MB; plus my database itself is around 1 GB. But the main thing is (if I could get it to work--and this is the second round of trying, so far without success), it would be much easier to utilize--just browse to the local file in the browser, no muss, no fuss with starting a VM, etc.

      But, alas! It looks like perl/DBI cannot work on Windows outside of a VM. Does anyone here have it running natively, sans VM?

      Blessings,

      ~Polyglot~

        G'day Polyglot,

        Firstly, I'm not a big MSWin user and mostly avoid working with it directly. So, feel free to question anything that follows.

        "... downgrading to Windows 11." [my additional emphasis]

        To the best of my knowledge, "Windows 11" is the latest MSWin offering. Perhaps a typo, or misunderstanding, with "downgrading".

        "Does anyone here have it running natively, sans VM?"

        Yes, I do. From cmd.exe:

        Microsoft Windows [Version 10.0.19045.2364] (c) Microsoft Corporation. All rights reserved. C:\Users\ken>perlmodver DBI Module: DBI Version: 1.642 Location: C:/Users/ken/local/opt/strawberry_perl/5_026_003/install/per +l/vendor/lib/DBI.pm C:\Users\ken>perlmodver DBD::mysql Module: DBD::mysql Version: 4.049 Location: C:/Users/ken/local/opt/strawberry_perl/5_026_003/install/per +l/vendor/lib/DBD/mysql.pm

        perlmodver is a quick-and-dirty script that I set up some years ago. It determines if modules are installed and, if so, their version and location.

        C:\Users\ken>where perlmodver C:\Users\ken\local\bin\perlmodver.bat C:\Users\ken>more C:\Users\ken\local\bin\perlmodver.bat @echo off perl -E "my ($err_msg, $missing); BEGIN { $err_msg = q{}; $missing = 0 +; eval { require %1; 1; } or ($err_msg, $missing) = ($@,1); } say q{M +odule: %1}; if ($missing) { say qq{Not installed.\n\@INC:}; say qq{\t +$_} for @INC; say qq{ERROR MESSAGE:\n$err_msg}; } else { say qq{Versi +on: $%1::VERSION\nLocation: $INC{q{%1} =~ s{::}{\/}gr . q{.pm}}}; }"

        I would have installed StrawberryPerl v5.26.3 about four years ago; my memory of doing this is now somewhat hazy. I'm 99% certain that I would have installed the DBI and DBD::mysql modules via the cpan utility.

        If you're installing via cpan — there are other utilities to do the same, e.g. cpanm & cpanp — ensure that cpan.exe (or equivalent) is in the same bin/ directory as perl.exe.

        C:\Users\ken>where perl C:\Users\ken\local\opt\strawberry_perl\5_026_003\install\perl\bin\perl +.exe C:\Users\ken>where cpan C:\Users\ken\local\opt\strawberry_perl\5_026_003\install\perl\bin\cpan +.bat

        You will need to install the DBI and DBD::mysql modules with the Perl version you're using. You can't simply copy them from another installation and expect them to work. I suspect this may be (at least part of) the problem you describe in "Re^2: Perl XAMPP DB Connect issue (Windows/Strawberry?)"; although, I am somewhat guessing about that.

        — Ken

        But, alas! It looks like perl/DBI cannot work on Windows outside of a VM. Does anyone here have it running natively, sans VM?

        Using my normal portable-based installation of Strawberry Perl, which came pre-installed with DBI and DBD::mysql (I didn't have to install those at all, because strawberry ships with them)

        C:> perl -V:myuname myuname='Win32 strawberry-perl 5.32.1.1 #1 Sun Jan 24 15:00:15 2021 x6 +4'; C:> perl -MDBI -MDBD::mysql -le "print join qq(\t), $DBI::VERSION, $DB +D::mysql::VERSION" 1.643 4.050

        winver shows Windows 10, 20H2 19042.2364

        Download mariadb-10.10.2-winx64.zip from https://dlm.mariadb.com/browse/mariadb_server/214/1565/winx64-packages/

        Follow instructions here to take the minimal files for a "portable" MariaDB, including optional bin\mysql_install_db.exe and unmentioned bin\mysql.exe (to give me a client to test with)

        > .\bin\mysql_install_db.exe --datadir=data Running bootstrap Creating my.ini file 2023-01-03 11:57:26 0 [Note] C:\usr\local\apps\MariaDB.Portable\bin\my +sqld.exe (server 10.10.2-MariaDB) starting as process 3752 ... Removing default user Creation of the database was successful > start bin\mysqld.exe --console (opens in new window: shows port 3306)

        Logon as root and create user pryrt and database test_db, similar to incantations here:

        MariaDB [(none)]> CREATE USER pryrt@localhost IDENTIFIED BY 'password' +; Query OK, 0 rows affected (0.015 sec) MariaDB [(none)]> CREATE DATABASE test_db; Query OK, 1 row affected (0.002 sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON test_db.* TO pryrt@localhost + IDENTIFIED BY 'password'; Query OK, 0 rows affected (0.014 sec) MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> quit Bye

        Verify from command-line that pryrt user works:

        > bin\mysql -u pryrt -ppassword test_db ... logged in okay, and quit...

        Prove that the Strawberry pre-installed DBI & DBD::mysql is sufficient to connect to a running MariaDB/MySQL database:

        > perl -MDBI -le "print DBI->connect('DBI:mysql:database=test_db', 'pr +yrt', 'password');" DBI::db=HASH(0x36eca40) C:\usr\local\apps\MariaDB.Portable > perl -MDBI -le "print DBI->connect('DBI:mysql:database=test_db', 'pr +yrt', 'passwordx');" DBI connect('database=test_db','pryrt',...) failed: Access denied for +user 'pryrt'@'localhost' (using password: YES) at -e line 1.

        (second run was used to prove that it would show an error rather than "DBI::db=HASH(0x....)" if there was a problem)

        And this is someone who has only touched MariaDB/MySQL a few times as briefly as possible; in Perl, I am more likely to use DBD::SQLite or DBD::CSV.

        But the assertion that "It looks like perl/DBI cannot work on Windows outside of a VM" is easily falsifiable even by someone with my limited database skillset -- even with the hidden MariaDB/MySQL assumption that you baked into that (because with DBD::SQLite or DBD::CSV , you don't need an external application for the database at all, and the sequence to getting it working is even easier)

        Whether you want to continue going down the XAMPP road is up to you. But if you're not married to the idea of XAMPP's Apache as the server, and outdated CGI as the interface, (and assuming you don't need the PHP capabilities), and instead just want a simple "portable"(ish) webserver with Perl, then might I recommend:

        • use my above sequence to prove to yourself that the fault doesn't lie in strawberry portable (you might need to start with a clean unzip from the portable, to avoid the weird state you are currently in after all your experimentation); use portableshell.bat (which shipped with strawberry) to make sure the environment is right (or set up the PATH yourself, as listed elsewhere in this discussion), so all perl should be run from that environment.
        • Pure Strawberry Perl (no XAMPP first!)
        • use cpanm DBD::MariaDB to install what other monks have recommended as a superior interface to MySQL/MariaDB, though DBD::mysql is functional at my level of usage
        • Use Mojolicious as your framework and starting with Mojolicious::Guides::Tutorial to help you get started
          • it comes with the Morbo server, so you don't need Apache or other webserver software at all.
          • once again, I am not an expert (so cannot really help), but that Tutorial was enough to enable me to get some simple Mojolicious::Lite -based scripts running through my shared webhost's server (that is: you don't need to use their morbo server, though you can if that's what you want; if you already have a working server, Mojolicious/Mojolicious::Lite will work fine through the Common Gateway Interface)
          • Alternately, other monks prefer Dancer2, but I cannot say anything about that

        Does anyone here have it running natively, sans VM

        Q.E.D.

Re^3: Perl XAMPP DB Connect issue (Windows/Strawberry?)
by swl (Parson) on Jan 01, 2023 at 04:19 UTC

    Is the Strawberry Perl c\bin directory in your path? If not then external DLLs cannot be located by the system and nothing that depends on them will work. In this case the file you refer to, mysql.xs.dll depends on libmysql__.dll. If that file is not in the path then the bindings will not work. The .xs.dll file is also the compiled XS bindings, not the mysql DLL.

    If you have downloaded a portable version of Strawberry perl, which from memory is what Chocolatey distributes, then you need to run the portableshell.bat script to set up the paths, or manually prepend them to your path. This script is at the top level of the Strawberry perl distribution.

    (Edited a few minutes after posting to clarify reference to .xs.dll file.)

      There is no "portableshell.bat" anywhere in the xampp directory tree. The only thing "portable" is a "Portable.pm" in the "C:\xampp\perl\vendor\lib\" and "C:\xampp\perl\vendor\lib\CPAN\Mini\" directories -- the former having 6,643 bytes as compared to the 388 bytes of the latter. I doubt they are what is needed.

      Blessings,

      ~Polyglot~

        In that case you can download the batch script from the Strawberry Perl github repo and save it to the top level of the perl distribution on your machine.

        Edit: Although you note in 11149261 that you have already downloaded a portable strawberry perl so should have this file.

        However, if all you want is to add the relevant paths then you can also run this code in your cmd shell before calling any perl code, updating the first path accordingly:

        set ST_PATH=c:\path\to\strawberry_perl_dir set PATH=%ST_PATH%\perl\site\bin;%ST_PATH%\bin;%ST_PATH%\c\bin;%PATH%

        If you are using powershell then the process is the same but the syntax will differ.

        The above process can also be done in a BEGIN block in your perl scripts but that does not help with running other perl scripts not under your control such as Makefile.PL scripts.

        Edit 2: All the above assumes you are working with a Strawberry Perl distribution. The XAMPP distribution does not include the c/bin directory. It also seems to be compiled using MSVC which, if I understand things correctly, means its DLLs will not work with Strawberry Perl since it is compiled using MINGW GCC. So you will likely need to find some way for your application to call out to the Strawberry Perl stack and not the XAMPP perl stack.

Re^3: Perl XAMPP DB Connect issue (Windows/Strawberry?)
by bliako (Monsignor) on Jan 03, 2023 at 18:09 UTC
    The file is not compatible for some reason.

    If that file is present, then this usually happens when perl.exe has been changed but the current *.xs.dll have not been rebuilt with this new perl.exe. Or when multiple perl.exe exist in your computer and the one you are using now is not the one used to compile/create the xs.dll file.