CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Can't locate DBD/mysql.pm error

 



Fishhead
Novice

Apr 21, 2016, 8:09 PM

Post #1 of 19 (4848 views)
Can't locate DBD/mysql.pm error Can't Post

My site is an auction for the commercial fishing industry. It has been up and running since 2011. It is currently located on a shared hosting site and I am in the process of moving it to a VPS site on another company's server.

I have move all the files and database to the new location and I have been testing everything before I have the DNS pointed to a the new location. For the most part everything looks good. I have an archive section, where a user can look at tables of past sales. These are generated from data stored in a mysql database. The display of past sales works fine.

However, when I test a new sale I get an error. For speed in testing I have been using a "buy-it-now" feature rather than have to wait for an auction to end.

The error message is:


Quote
install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains: /home/jeffer36/perl/home/jeffer36/perl5/lib/perl5 /home/jeffer36/perl/home/jeffer36/perl5/lib/perl5/x86_64-linux-thread-multi /home/jeffer36/perl/home/jeffer36/perl/usr/local/lib64/perl5 /home/jeffer36/perl/home/jeffer36/perl/usr/local/share/perl5 /home/jeffer36/perl/home/jeffer36/perl/usr/lib64/perl5/vendor_perl /home/jeffer36/perl/home/jeffer36/perl/usr/share/perl5/vendor_perl /home/jeffer36/perl/home/jeffer36/perl/usr/lib64/perl5 /home/jeffer36/perl/home/jeffer36/perl/usr/share/perl5 /home/jeffer36/perl/usr/local/lib64/perl5 /home/jeffer36/perl/usr/local/share/perl5 /home/jeffer36/perl/usr/lib64/perl5/vendor_perl /home/jeffer36/perl/usr/share/perl5/vendor_perl /home/jeffer36/perl/usr/lib64/perl5 /home/jeffer36/perl/usr/share/perl5 /home/jeffer36/perl. /home/jeffer36/perl5/lib/perl5 /home/jeffer36/perl5/lib/perl5/x86_64-linux-thread-multi /home/jeffer36/perl/usr/local/lib64/perl5 /home/jeffer36/perl/usr/local/share/perl5 /home/jeffer36/perl/usr/lib64/perl5/vendor_perl /home/jeffer36/perl/usr/share/perl5/vendor_perl /home/jeffer36/perl/usr/lib64/perl5 /home/jeffer36/perl/usr/share/perl5 /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at (eval 16) line 3, <BUYERFILE> line 34.
Perhaps the DBD::mysql perl module hasn't been fully installed,
or perhaps the capitalisation of 'mysql' isn't right.
Available drivers: DBM, ExampleP, File, Gofer, Proxy, SQLite, Sponge.
at ../auction/buyit.pl line 283


The main auction program begins with:

Quote
#!/usr/bin/perlml

BEGIN {
my $base_module_dir = (-d '/home/jeffer36/perl' ? '/home/jeffer36/perl' : ( getpwuid($>) )[7] . '/perl/');
unshift @INC, map { $base_module_dir . $_ } @INC;
}


I have installed the DBD::mysql module and it is located at:

Quote
/perl/usr/lib/perl5/5.8.8/x86_64linux


And lastly, here is the code for the section of buy-it-now script that should store the sale information in the database:


Code
## connect to database 
my $dbh = DBI->connect("DBI:mysql:$db:$server", $userid, $passwd);

## prepare and execute query
my $query = "INSERT INTO closedauctions (seller, sellerusername, category, title, bids, pounds, description, winningbid, price_per_pound, highbidder, buyerusername, month, day, year, itemnum, filename) VALUES(\"$sellername\",\"$sellerusername\",\"$quota\", \"$category\", 1, \"$pounds\", \"$desc\", \"$buyit\", \"$price_per_pound\", \"$buyername\",\"$buyerusername\", \"$month\", \"$day\", \"$year\", \"$form{'ITEM'}\", \"$cat\")";
my $sth = $dbh->prepare($query) || die "Could not prepare SQL statement ... maybe invalid?";
$sth->execute() || die "Could not execute SQL statement ... maybe invalid?";

## disconnect from database
$dbh->disconnect;


The line beginning with "my $dbh = DBI->connect ..." is line 283 in buyit.pl.

Can anyone help me get this working? I am assuming that I simply not pointing the script to look in the right spot. but what is strange is the code does work on the current server, just not on the new one.

Thanks

Pete


Zhris
Enthusiast

Apr 21, 2016, 10:48 PM

Post #2 of 19 (4843 views)
Re: [Fishhead] Can't locate DBD/mysql.pm error [In reply to] Can't Post

If you are sure its installed at '/perl/usr/lib/perl5/5.8.8/x86_64linux' then a consistent quick fix would be to add this path to the @INC array. If you used cpanel's tool to install the module then I would have thought it would have installed under your home directory covered by the existing @INC paths, can you confirm.


Code
unshift @INC, map { $base_module_dir . $_ } @INC; 
unshift @INC, '/perl/usr/lib/perl5/5.8.8/x86_64linux';


Chris


Fishhead
Novice

Apr 22, 2016, 12:22 AM

Post #3 of 19 (4839 views)
Re: [Zhris] Can't locate DBD/mysql.pm error [In reply to] Can't Post

Chris

Thanks for the response. I did install using cPanel. On the Perl module page toward the top the following is displayed:

Quote
Your Perl script needs to know how to find the modules in your path. You can do this by adding one of the two choices below to the top of your script:

#!/usr/bin/perl
use cPanelUserConfig;

or

#!/usr/bin/perlml


I use FileZilla for FTP. Using the search file feature for the Perl folder, /perl/usr/lib/perl5/5.8.8/x86_64linux, is where it is found.

There is also a Perl5 folder and it shows up twice. In /perl5/lib/perl5/86_64-linux/Bundle/DBD and in /perl5/lib/perl5/86_64-linux/DBD.

Now back to your suggestion. I modified the code to read

Code
BEGIN { 
my $base_module_dir = (-d '/home/jeffer36/perl' ? '/home/jeffer36/perl' : ( getpwuid($>) )[7] . '/perl/');
unshift @INC, '/perl/usr/lib/perl5/5.8.8/x86_64linux';
}


and received the following error

Quote
install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains: /perl/usr/lib/perl5/5.8.8/x86_64linux /home/jeffer36/perl5/lib/perl5 /home/jeffer36/perl5/lib/perl5/x86_64-linux-thread-multi /home/jeffer36/perl/usr/local/lib64/perl5 /home/jeffer36/perl/usr/local/share/perl5 /home/jeffer36/perl/usr/lib64/perl5/vendor_perl /home/jeffer36/perl/usr/share/perl5/vendor_perl /home/jeffer36/perl/usr/lib64/perl5 /home/jeffer36/perl/usr/share/perl5 /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at (eval 16) line 3, <BUYERFILE> line 67.
Perhaps the DBD::mysql perl module hasn't been fully installed,
or perhaps the capitalisation of 'mysql' isn't right.
Available drivers: DBM, ExampleP, File, Gofer, Proxy, SQLite, Sponge.
at ../auction/buyit.pl line 283


I do not seem to be making much progress.

Lastly, I tried keeping the original line of code but changing perl to perl5, so it looked like this:

Quote
my $base_module_dir = (-d '/home/jeffer36/perl5' ? '/home/jeffer36/perl5' : ( getpwuid($>) )[7] . '/perl5/');
unshift @INC, map { $base_module_dir . $_ } @INC;


And I got this error message:

Quote
install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains: /home/jeffer36/perl5/home/jeffer36/perl5/lib/perl5 /home/jeffer36/perl5/home/jeffer36/perl5/lib/perl5/x86_64-linux-thread-multi /home/jeffer36/perl5/home/jeffer36/perl/usr/local/lib64/perl5 /home/jeffer36/perl5/home/jeffer36/perl/usr/local/share/perl5 /home/jeffer36/perl5/home/jeffer36/perl/usr/lib64/perl5/vendor_perl /home/jeffer36/perl5/home/jeffer36/perl/usr/share/perl5/vendor_perl /home/jeffer36/perl5/home/jeffer36/perl/usr/lib64/perl5 /home/jeffer36/perl5/home/jeffer36/perl/usr/share/perl5 /home/jeffer36/perl5/usr/local/lib64/perl5 /home/jeffer36/perl5/usr/local/share/perl5 /home/jeffer36/perl5/usr/lib64/perl5/vendor_perl /home/jeffer36/perl5/usr/share/perl5/vendor_perl /home/jeffer36/perl5/usr/lib64/perl5 /home/jeffer36/perl5/usr/share/perl5 /home/jeffer36/perl5. /home/jeffer36/perl5/lib/perl5 /home/jeffer36/perl5/lib/perl5/x86_64-linux-thread-multi /home/jeffer36/perl/usr/local/lib64/perl5 /home/jeffer36/perl/usr/local/share/perl5 /home/jeffer36/perl/usr/lib64/perl5/vendor_perl /home/jeffer36/perl/usr/share/perl5/vendor_perl /home/jeffer36/perl/usr/lib64/perl5 /home/jeffer36/perl/usr/share/perl5 /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at (eval 16) line 3, <BUYERFILE> line 68.
Perhaps the DBD::mysql perl module hasn't been fully installed,
or perhaps the capitalisation of 'mysql' isn't right.
Available drivers: DBM, ExampleP, File, Gofer, Proxy, SQLite, Sponge.
at ../auction/buyit.pl line 283


This is getting frustrating!

Pete


Zhris
Enthusiast

Apr 22, 2016, 2:24 AM

Post #4 of 19 (4835 views)
Re: [Fishhead] Can't locate DBD/mysql.pm error [In reply to] Can't Post

Apologies for the confusion, I didn't mean for you to replace the previous line, I included it so that you knew to put the new line underneath it. This won't help though.

Can you confirm that the pm file exists at /perl/usr/lib/perl5/5.8.8/x86_64linux/DBD/mysql.pm. If not, then locate it. Fundamentally the module package name DBD::mysql will be converted to a relative path DBD/mysql.pm then joined onto the @INC path /perl/usr/lib/perl5/5.8.8/x86_64linux to produce the absolute path /perl/usr/lib/perl5/5.8.8/x86_64linux/DBD/mysql.pm. I suspect its probably in one of the perl5 directories.

Leave the existing code in the begin block alone for now, just unshift or push new paths onto the @INC array underneath.

Personally I don't remember ever having to make @INC modifications after using cpanel's perl module section, they installed into my home directory as expected.

Chris


(This post was edited by Zhris on Apr 22, 2016, 2:30 AM)


Fishhead
Novice

Apr 22, 2016, 8:56 AM

Post #5 of 19 (4818 views)
Re: [Zhris] Can't locate DBD/mysql.pm error [In reply to] Can't Post

Chris, again thanks for the help.

Using FileZilla file search feature this is what I find for the location of mysql.pm. I am showing path, file size, and permissions:

perl folder -
/perl/usr/lib/perl5/5.8.8/CGI/Session/Driver - 4188 - 0644

/perl/usr/lib/perl5/5.8.8/x86_64-linux - 4188 - 0644

perl5 folder -
/perl5/lib/perl5/CGI/Session/Driver - 4188 - 0444

/perl5/lib/perl5/HDB/MOD - 3328 - 0444

/perl5/lib/perl5/x86_64-linux/Bundle/DBD 250 - 0444

/perl5/lib/perl5/x86_64-linux/DBD 62,706 - 0444

The last two in the perl5 list were installed following using the cPanel installation for DBD::mysql. The file size is very different for the others.

I tried something else. I added "use DBD::mysql;" to the beginning of my auction.pl file, following the "Begin" statement. I included the additional line of code that you gave me and repeatedly changed the text to try and find the mysql.pm file and nothing seemed to work.

I received versions of this error:

Quote
Can't locate DBD/mysql.pm in @INC (@INC contains: /perl5/lib/perl5/x86_64-linux /home/jeffer36/perl/home/jeffer36/perl5/lib/perl5


I am getting more and more confused. Everything has been working fine on the current-old site. It only not working on the new-temporary site.

Pete


Zhris
Enthusiast

Apr 22, 2016, 3:32 PM

Post #6 of 19 (4809 views)
Re: [Fishhead] Can't locate DBD/mysql.pm error [In reply to] Can't Post

It looks like DBD::mysql is in one of the perl5 directories. Change your begin block to the following, ensure you use DBD::mysql afterwards.


Code
BEGIN  
{
my $base_module_dir = (-d '/home/jeffer36/perl' ? '/home/jeffer36/perl' : ( getpwuid($>) )[7] . '/perl/');
unshift @INC, map { $base_module_dir . $_ } @INC;
unshift @INC, '/perl5/lib/perl5', '/perl5/lib/perl5/x86_64-linux', '/perl5/lib/perl5/x86_64-linux/Bundle';
}

use DBD::mysql;


This assumes /perl5 is at the root of your system, not relative to /home/jeffer36, otherwise prepend.

Chris


(This post was edited by Zhris on Apr 22, 2016, 3:50 PM)


Fishhead
Novice

Apr 22, 2016, 4:13 PM

Post #7 of 19 (4795 views)
Re: [Zhris] Can't locate DBD/mysql.pm error [In reply to] Can't Post

Chris

When I put your new code in I get a 500 error. If I block the use DBD::mysql line, I receive the same error that I have been getting.

However, today I have also tried a few things. I want to think that I am making progress.

I left the original Begin code as it was from the first time. Then I added below that code the line:

Code
use lib '/home/jeffer36/perl5/lib/perl5/x86_64-linux/Bundle';


When I run this I get a different error message:

Quote
DBD::mysql initialisation failed: Can't locate object method "driver" via package "DBD::mysql" at /usr/lib64/perl5/DBI.pm line 802, <BUYERFILE> line 76.

Perhaps the capitalisation of DBD 'mysql' isn't right. at ../auction/buyit.pl line 283


The reference to DBI made me double check that it was installed. It went into perl5 also. So I added this line also:

Code
use lib '/home/jeffer36/perl5/lib/perl5/CGI/Session/Driver';


And I go a new error message:

Quote
Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI"?) at ../auction/buyit.pl line 283, <BUYERFILE> line 76.


I am assuming that I am continuing to have problems pointing to where the files are stored.

Thoughts or suggestion?

Pete


Zhris
Enthusiast

Apr 22, 2016, 4:42 PM

Post #8 of 19 (4792 views)
Re: [Fishhead] Can't locate DBD/mysql.pm error [In reply to] Can't Post

Ok you've made head way on your original problem and discovered the path to DBD::mysql is in fact "/home/jeffer36/perl5/lib/perl5/x86_64-linux/Bundle", and the perl5 directory is not at the root of your system.

Your new error message looks as though it identifies a problem with the dsn you pass to DBI::connect. In your original code what do $db and $server contain, ensure they are appropriately formatted as per the DBD::mysql documentation i.e. prepended with database= and host=. Note the semicolon ; not colon : separating database, host and port components.


Code
DBI:mysql:database=$database;host=$hostname;port=$port;


Ensure you use DBI. You don't need to use DBD::mysql, I added in earlier code for testing purposes.

Don't use multiple use lib statements, it accepts an array i.e. use lib '/path1', '/path2';

You don't add paths to specific modules, as mentioned earlier, module package names are converted to relative paths for you.


Code
use lib '/home/jeffer36/perl5/lib/perl5/CGI/Session/Driver'; 

use lib '/home/jeffer36/perl5/lib/perl5';
use CGI::Session; # will look for pm file /home/jeffer36/perl5/lib/perl5/CGI/Session.pm


For both DBI and CGI::Session, you don't need to use the specific drivers. You supply this information via a dsn argument and the parent module takes care of loading the driver at runtime.

Your script header should probably look something like the following now:


Code
BEGIN  
{
my $base_module_dir = (-d '/home/jeffer36/perl' ? '/home/jeffer36/perl' : ( getpwuid($>) )[7] . '/perl/');
unshift @INC, map { $base_module_dir . $_ } @INC;
}

use lib '/home/jeffer36/perl5/lib/perl5', '/home/jeffer36/perl5/lib/perl5/x86_64-linux', '/home/jeffer36/perl5/lib/perl5/x86_64-linux/Bundle';
use DBI;
use CGI::Session;


Chris


(This post was edited by Zhris on Apr 22, 2016, 4:57 PM)


Fishhead
Novice

Apr 22, 2016, 6:55 PM

Post #9 of 19 (4783 views)
Re: [Zhris] Can't locate DBD/mysql.pm error [In reply to] Can't Post

Chris, thanks for the encouragement.

The original code in the buy-it-now file is:

Code
my $db = "jeffer36_closedauctions"; 
my $server = "localhost";

## connect to database
my $dbh = DBI->connect("DBI:mysql:$db:$server", $userid, $passwd);


The only change here from what is currently working is the identifier part of $db (ie jeffer36_). This is the same wording that is working when calling the archives of past sales from the database.

I am a bit confused about your comment to semicolons rather than colons.

I substituted your code for what I had been playing around with, it now looks like:

Code
#!/usr/bin/perlml 

BEGIN {
my $base_module_dir = (-d '/home/jeffer36/perl' ? '/home/jeffer36/perl' : ( getpwuid($>) )[7] . '/perl/');
unshift @INC, map { $base_module_dir . $_ } @INC;
}

use lib '/home/jeffer36/perl5/lib/perl5','/home/jeffer36/perl5/lib/perl5/x86_64-linux','/home/jeffer36/perl5/lib/perl5/x86_64-linux/Bundle';

use POSIX qw(strftime);
use File::Copy;
use strict;
use CGI;
use CGI::Session;
use CGI::Carp qw(fatalsToBrowser);
use File::CounterFile;
use Data::Dumper;
use DBI;


When I run this I get the following error:

Quote
install_driver(mysql) failed: Can't load '/home/jeffer36/perl5/lib/perl5/x86_64-linux/auto/DBD/mysql/mysql.so' for module DBD::mysql: /home/jeffer36/perl5/lib/perl5/x86_64-linux/auto/DBD/mysql/mysql.so: undefined symbol: PL_perl_destruct_level at /usr/lib64/perl5/DynaLoader.pm line 200, <BUYERFILE> line 78.
at (eval 16) line 3
Compilation failed in require at (eval 16) line 3, <BUYERFILE> line 78.
Perhaps a required shared library or dll isn't installed where expected
at ../auction/buyit.pl line 283


It is similar to the earlier error, but slightly different.

My read on the earlier error message was not a mis-configuration of the $db and $server values but still not clearly pointing to the modules correctly.

I have been operating with the belief that since the code works fine on one server, when it is not working well on the new server it is an issue of not clearly identifying where everything is located.

Pete


Zhris
Enthusiast

Apr 22, 2016, 9:46 PM

Post #10 of 19 (4773 views)
Re: [Fishhead] Can't locate DBD/mysql.pm error [In reply to] Can't Post


Quote
I am a bit confused about your comment to semicolons rather than colons.

I have been operating with the belief that since the code works fine on one server, when it is not working well on the new server it is an issue of not clearly identifying where everything is located.

My read on the earlier error message was not a mis-configuration of the $db and $server values but still not clearly pointing to the modules correctly.


Your belief is understandable, but its not always straight forward. My understanding is that your current dsn syntax worked on your old system and thus should work on the new system. From my standpoint, DBD::mysql documents a different dsn syntax and it made sense to suggest an up to date modification. There is always the possibility that your old system used an older version of DBD::mysql and the latest version you just installed isn't backwards compatible. Its always worth a shot, I still suggest this change regardless.

The error message in question related to the dsn, particularly as it suggested the casing of the mysql driver component could be incorrect.

You should remove '/home/jeffer36/perl5/lib/perl5/x86_64-linux/Bundle' from your lib imports, I hadn't realized Bundle was a module namespace that contained a legacy (Bundle::)DBD::mysql version. This was probably the cause of these previous dsn issues when it was your only lib import.


Quote
When I run this I get the following error:

Quote
install_driver(mysql) failed: Can't load '/home/jeffer36/perl5/lib/perl5/x86_64-linux/auto/DBD/mysql/mysql.so' for module DBD::mysql: /home/jeffer36/perl5/lib/perl5/x86_64-linux/auto/DBD/mysql/mysql.so: undefined symbol: PL_perl_destruct_level at /usr/lib64/perl5/DynaLoader.pm line 200, <BUYERFILE> line 78.
at (eval 16) line 3
Compilation failed in require at (eval 16) line 3, <BUYERFILE> line 78.
Perhaps a required shared library or dll isn't installed where expected
at ../auction/buyit.pl line 283

It is similar to the earlier error, but slightly different.


The error still relates to the driver, but indicates a new issue. I have done a little research (Google) but haven't been able to draw any definitive conclusions yet. PL_perl_destruct_level indicates a compilation issue to me. http://search.cpan.org/~michielb/DBD-mysql/lib/DBD/mysql/INSTALL.pod may also help. I'll update if I have further information.

Chris


Fishhead
Novice

Apr 22, 2016, 10:24 PM

Post #11 of 19 (4766 views)
Re: [Zhris] Can't locate DBD/mysql.pm error [In reply to] Can't Post

Chris

On the first issue of colons vs semicolons, if I understood what you were suggesting, it did not seem to make a difference.

I may well have misunderstood. Below is the text of the code from the buy-it-now script which should send the sale information to the database.

Original code:

Code
my $dbh = DBI->connect("DBI:mysql:$db:$server", $userid, $passwd);


This is the changed code:

Changed code:

Code
my $dbh = DBI->connect("DBI;mysql;$db;$server", $userid, $passwd);


The error message is the same.

Quote
Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI"?) at ../auction/buyit.pl line 284, <BUYERFILE> line 79.


I need to better digest the rest of your comments. It is Friday night here, Pacific time, my brother and his wife just left. After a couple of bottles of Zinfandel, I do not think it wise to start to get creative any more than I have to night.

I do know that there is a solution to this problem and I appreciate your help.

Pete


Zhris
Enthusiast

Apr 24, 2016, 7:43 AM

Post #12 of 19 (4741 views)
Re: [Fishhead] Can't locate DBD/mysql.pm error [In reply to] Can't Post


Quote
On the first issue of colons vs semicolons, if I understood what you were suggesting, it did not seem to make a difference.


I believe it probably won't make a difference for various reasons, but its the documented format. The change you made is not quite right:


Code
my $dsn = "DBI:mysql:$db:$server"; 
my $dsn = "DBI;mysql;$db;$server";
my $dsn = "DBI:mysql:database=$db;host=$server";

my $dbh = DBI->connect($dsn, $userid, $passwd);


I'm surprised you got a "Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI"?)" error, that would suggest you removed "use DBI".

However, this appears to be stepping backwards a little, your prior error indicated dsn issues had been resolved but there was an issue loading the driver.

Heres a standalone script which exhibits everything we have discussed / discovered. Its a good idea to install, run and modify this separately from your buyit.pl auction script until you have all issues resolved.


Code
#!/usr/bin/perlml  

BEGIN {
my $base_module_dir = (-d '/home/jeffer36/perl' ? '/home/jeffer36/perl' : ( getpwuid($>) )[7] . '/perl/');
unshift @INC, map { $base_module_dir . $_ } @INC;
}

use lib '/home/jeffer36/perl5/lib/perl5','/home/jeffer36/perl5/lib/perl5/x86_64-linux';

use strict;
use warnings FATAL => qw(all);
use CGI::Carp qw(fatalsToBrowser);
use DBI;

my $db = "jeffer36_closedauctions";
my $server = "localhost";
my $dsn = "DBI:mysql:database=$db;host=$server";
my $userid = 'userid';
my $passwd = 'passwd';

my $dbh = DBI->connect($dsn, $userid, $passwd);

print "content-type: text/plain\n\n";
print "completed successfully\n";


Chris


(This post was edited by Zhris on Apr 24, 2016, 7:47 AM)


FishMonger
Veteran / Moderator

Apr 24, 2016, 9:04 AM

Post #13 of 19 (4735 views)
Re: [Zhris] Can't locate DBD/mysql.pm error [In reply to] Can't Post


In Reply To

Quote
On the first issue of colons vs semicolons, if I understood what you were suggesting, it did not seem to make a difference.


I believe it probably won't make a difference for various reasons, but its the documented format. The change you made is not quite right:


Code
my $dsn = "DBI:mysql:$db:$server"; 
my $dsn = "DBI;mysql;$db;$server";
my $dsn = "DBI:mysql:database=$db;host=$server";

my $dbh = DBI->connect($dsn, $userid, $passwd);


Chris

Actually, it does make a big difference. You must use a colon between the class, driver, and the next group of params but you can use either a colon or semi colon to separate the other params. If you're using the more verbose syntax, I believe you must use the semi colon as the separator, but I have not confirmed that.

I always only use colons and the less verbose syntax because it's cleaner and I don't have to remember the details of when and where I can or can not use the semi colons.

So, instead of:

Code
my $dsn = "DBI:mysql:database=$db;host=$server";


I'd use:

Code
my $dsn = "DBI:mysql:$db:$server";


However, there is one advantage to using the more verbose syntax and that is you can put those params in any order. When using the shorter syntax, the params must be in a specific order.


(This post was edited by FishMonger on Apr 24, 2016, 9:05 AM)


Fishhead
Novice

Apr 24, 2016, 10:27 AM

Post #14 of 19 (4730 views)
Re: [Zhris] Can't locate DBD/mysql.pm error [In reply to] Can't Post

Chris

I copied your test code and saved it as test.pl and ran it. I received the following error message:

Quote
Software error:

Can't load '/home/jeffer36/perl5/lib/perl5/x86_64-linux/auto/DBI/DBI.so' for module DBI: /home/jeffer36/perl5/lib/perl5/x86_64-linux/auto/DBI/DBI.so: undefined symbol: PL_tainting at /usr/lib64/perl5/DynaLoader.pm line 200.
at /home/jeffer36/perl5/lib/perl5/x86_64-linux/DBI.pm line 286
BEGIN failed--compilation aborted at /home/jeffer36/perl5/lib/perl5/x86_64-linux/DBI.pm line 286.
Compilation failed in require at test.pl line 13.
BEGIN failed--compilation aborted at test.pl line 13.


Pete


Fishhead
Novice

Apr 24, 2016, 10:38 AM

Post #15 of 19 (4729 views)
Re: [FishMonger] Can't locate DBD/mysql.pm error [In reply to] Can't Post

FishMonger

Thanks for helping out.

My original code was:

Code
my $dbh = DBI->connect("DBI:mysql:$db:$server", $userid, $passwd);


What you and Chris have suggested is:

Code
my $dsn = "DBI:mysql:$db:$server"; 
my $dbh = DBI->connect($dsn, $userid, $passwd);


Aren't these lines effectively equivalent?

Any light that you can shed on my original problem would be greatly appreciated.

My belief remains that some perl files are being stored in a different location on the new server and I am not pointing to them correctly.

Pete

Pete


Zhris
Enthusiast

Apr 24, 2016, 11:32 AM

Post #16 of 19 (4723 views)
Re: [FishMonger] Can't locate DBD/mysql.pm error [In reply to] Can't Post


Quote
Actually, it does make a big difference


A little bit of confusion, I was referring to the difference between the OP's original supposedly working dsn syntax and the verbose form I suggested. As you have clarified, they are both acceptable and thus makes no difference. I have always used the verbose form as documented by DBD::mysql, in fact I can't even find any mention of the less verbose form.

Chris


Zhris
Enthusiast

Apr 24, 2016, 11:54 AM

Post #17 of 19 (4719 views)
Re: [Fishhead] Can't locate DBD/mysql.pm error [In reply to] Can't Post

A quick Google search overwhelmingly suggests that DBI.so requires the PL_tainting symbol which isn't provided by the Perl interpreter you are using i.e. the current Perl interpreter did not build DBI.so. This is out of my realm. Since your original problem has been resolved, if you don't get further help via this thread, create a new thread with your new issues.

Chris


FishMonger
Veteran / Moderator

Apr 25, 2016, 8:40 AM

Post #18 of 19 (4708 views)
Re: [Zhris] Can't locate DBD/mysql.pm error [In reply to] Can't Post


Quote
I have always used the verbose form as documented by DBD::mysql, in fact I can't even find any mention of the less verbose form.

It's "mentioned" in both DBI and DBD::mysql docs, but it doesn't give detailed explanation.

DBI: going from the less verbose to the most verbose

Code
Examples of $data_source values are: 

dbi:DriverName:database_name
dbi:DriverName:database_name@hostname:port
dbi:DriverName:database=database_name;host=hostname;port=port


One or more of the older versions (I'm not sure which) gives more detailed explanation. I even recall that the older versions also included the username and password in the verbose example, which I don't think is supported any longer.


Code
#!/usr/bin/perl  

use 5.010;
use strict;
use warnings FATAL => 'all';
use DBI;

my $db = 'mysql';
my $host = 'localhost';
my $usr = 'root';
my $pwd = '******';
my $dsn = "DBI:mysql:$db";

my $dbh = DBI->connect( $dsn, $usr, $pwd, { RaiseError => 1 } )
or die DBI->errstr;

say 'connected';
$dbh->disconnect;



Quote
c:\test>db_test.pl
connected



Zhris
Enthusiast

Apr 25, 2016, 9:01 AM

Post #19 of 19 (4704 views)
Re: [FishMonger] Can't locate DBD/mysql.pm error [In reply to] Can't Post

Thank you for this information.

Chris

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives