Home: Perl Programming Help: DBI:
Compile error



Fritter
New User

Mar 5, 2009, 11:41 AM


Views: 7144
Compile error

Hi I'm new to perl and I wrote a script to connect to a mysql database i have but my problem is whenever i go to run it i get this error

Can't locate DBI.pm in @INC (@INC contains: /usr/perl5/5.8.4/lib/sun4-solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_perl/5.8.4/sun4-solaris-64int /usr/perl5/site_perl/5.8.4 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int /usr/perl5/vendor_perl/5.8.4 /usr/perl5/vendor_perl .) at connection.pl line 3.
BEGIN failed--compilation aborted at connection.pl line 3.


I have installed DBI on the SunOS 5.10 server which is running perl, v5.8.4 built for sun4-solaris-64int. Can somebody please help me or point me in the right direction? Thanks!


Code
 #!/usr/bin/perl 
print "Content-type: text/html nn";
use DBI; # Connect To Database
$database = "XXX";
$username = "XXX";
$password = "XXX";
$hostname = "localhost";
$db = DBI->connect("DBI:mysql:$database:$hostname", $username, $password);



1arryb
User

Mar 6, 2009, 9:13 AM


Views: 7138
Re: [Fritter] Compile error

Hi Fritter,

Well, you have a problem with your perl installation. This problem should compile as written.

One thing I noticed is that most L/Unix systems put perl in /usr/lib/perl5. You may have put DBI there by mistake. How did you install DBI?

Also, once you get your DBI (and you will also need DBD::mysql) installation straightened out, the dsn in your connect statement is wrong. It should be:

Code
$db = DBI->connect("DBI:mysql:database=$database;host=$hostname", $username, $password);


Cheers,

Larry


FishMonger
Veteran / Moderator

Mar 6, 2009, 11:01 AM


Views: 7135
Re: [1arryb] Compile error

Larry,

Both forms of the connect statement are valid. In fact, I never use the more verbose syntax.