1

I am trying to write data to a MySQL database using Perl. However, when I run my script I get the error below:

Can't locate loadable object for module DBD::mysql in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at LargeLDAPSearch.pl line 10.

I do have these "use" statements and following code. This is just a small excerpt, because the script worked before I tried a DB connection:

use DBD::mysql;
use strict;
use warnings;
my $query_handle;

my ($platform,$database,$host,$port,$db_user,$pw) = ("mysql","results","localhost","3306","root","mysql123");

my $dsn = "dbi:$platform:$database:$host:$port";

my $connect = DBI->connect($dsn,$db_user,$pw) || die "Could not connect to database";

my $query_insert = "INSERT INTO " . $dbname . "(uid,status,lstpwdset,reset) VALUES (" . $strSAMA . "," . $strAcctControl . "," . $pwLS . "," . $reset . ")";

$query_handle = $connect->prepare($query_insert);
$query_handle->execute();

I have gone into my Perl folder on my local, and searched the lib file directory. In the /lib/ subfolder, I have two folders, a DBI and a DBD subfolder, and I have MySQL subfolder in DBD and also a DBD subfolder with a MySQL subfolder under DBI. /lib/DBD/mysql/ & `/lib/DBI/DBD/mysql/``

This could be the error, fodlers in two spots. I went to the CPAN website, and have tried the manual isntall steps, and i receive an install error of DBI regarding SQLLite.

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
cquadrini
  • 769
  • 2
  • 12
  • 25
  • I had the same problem. But it does seem that ActiveState perl can work with DBDLite installed with it. Mine works with and without installing perl-DBD-MySQL using YUM. Also works with and without having `use DBD::mysql` in my script. I did install MySQL on the box running the Perl script (after experiencing the errors). Not sure if MySQL provided any library files etc to help. – guest Jun 30 '17 at 15:18
  • Have you installed both `DBI` and `DBD::mysql`? If so, how did you do it? This error sounds like `DBD::mysql` either isn't installed or wasn't installed correctly. – Dave Cross Apr 09 '12 at 16:17
  • When I run MakeFile.pl I get this `code It looks like you don't have a C compiler on your PATH, so you will not be able to compile C or XS extension modules. You can install GCC from the MinGW package using the Perl Package Manager by running: ppm install MinGW Checking if your kit is complete... Looks good Writing Makefile for Data::ShowTable Writing MYMETA.yml and MYMETA.json Press any key to continue . . .` Run cmd to install DBI err: `code ppm install DBI ppm install failed: install_driver(SQLite) failed: DBD::SQLite object version 1.33 does not match bootstrap parameter 1.35` – cquadrini Apr 09 '12 at 17:21
  • Don't cram these important bits of information into comments. Instead, edit, update, rewrite your question with the relevant bits. You seem to have borked your ActivePerl installation which uses a SQLite database to keep information on installed modules. Somehow it's loading a SQLite DLL that is a lower version than the version against which your distribution's `DBD::SQLite` was built against. – Sinan Ünür Apr 09 '12 at 17:54

2 Answers2

5

Install DBI and DBD::mysql using

C:\> ppm install DBI
C:\> ppm install DBD::mysql

You seem to be using ActivePerl, so use the facilities it provides you.

DBD::mysql does come with documentation:

From perl you activate the interface with the statement

use DBI;

After that you can connect to multiple MySQL database servers and send multiple queries to any of them via a simple object oriented interface. Two types of objects are available: database handles and statement handles. Perl returns a database handle to the connect method like so:

my $dbh = DBI->connect("DBI:mysql:database=$db;host=$host",
                  $user, $password, {RaiseError => 1});
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
  • I am giving you an up and the check for this answer. But for some reason my Active Perl Package Manager is not loading. I have rebooted my computer, and still nothing. I am going to uninstall it and reinstall and then reinstall the addons via CPAN. – cquadrini Apr 10 '12 at 14:06
  • As I said before: *you seem to have borked your ActivePerl installation. `ppm` uses a SQLite database to keep information on installed modules. Somehow it's loading a SQLite DLL that is a lower version than the version against which your distribution's DBD::SQLite was built against.* – Sinan Ünür Apr 10 '12 at 14:09
  • Download version 1.35 from CPAN or another vendor? – cquadrini Apr 10 '12 at 14:22
4

Do not use DBD::mysql. Do just use DBI. It will load your MySQL driver automagically.

daxim
  • 39,270
  • 4
  • 65
  • 132
Alberto
  • 499
  • 4
  • 23
  • 1
    I tried that as well before I made that post, and I get this error: `code install_driver(mysql) failed: Can't locate loadable object for module DBD::mysql in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at (eval 12) line 3. Compilation failed in require at (eval 12) line 3, line 2. Perhaps a module that DBD::mysql requires hasn't been fully installed` Maybe I didn't install it correctly. Not sure why I got a -1 one on this question. – cquadrini Apr 09 '12 at 17:11