LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   perl dbi:mysql shows error syntax error dbi:mysql ?? (http://www.linuxquestions.org/questions/linux-server-73/perl-dbi-mysql-shows-error-syntax-error-dbi-mysql-707466/)

haxpak 02-25-2009 10:48 AM

perl dbi:mysql shows error syntax error dbi:mysql ??
 
hello

i am trying to use perl to connect to mysql

my perl script looks like this:

Code:

#!/usr/bin/perl


use warnings;
use DBI;
use strict;

my $database = "project";
my $driver = "DBI:mysql";
my $dbh = DBI->connect($driver:$database, "root", "") or die "cant connect to mysql";

$dbh->do("insert into Cards values ('10896' , '1100')");
$dbh->disconnect;

but when i run the script i get error saying:
Quote:

syntax error at ./testdbi.pl line 10, near "$driver:"
Execution of ./testdbi.pl aborted due to compilation errors.
have issued the following commands
if it is of some use?

Code:

our @ary = DBI->available_drivers;
#foreach (keys %drivers)
foreach (@ary)
{
print "$_ \n";
}

exit;

it returned
Quote:

DBM
ExampleP
File
Gofer
Proxy
Sponge
mysql
also
Code:

%drivers = DBI->installed_drivers();
returns nothing

Code:

perl -MDBI -e 'DBI->installed_versions'
at shell returned the following:

Quote:

Perl : 5.010000 (x86_64-linux-thread-multi)
OS : linux (2.6.18-92.1.18.el5)
DBI : 1.607
DBD::mysql : 4.005
DBD::Sponge : 12.010002
DBD::Proxy : install_driver(Proxy) failed: Can't locate RPC/PlClient.pm in @INC
DBD::Gofer : 0.011565
DBD::File : 0.35
DBD::ExampleP : 12.010007
DBD:BM : 0.03
please help me

haxpak 02-25-2009 11:29 AM

someone please reply

knudfl 02-25-2009 12:58 PM

'Duplicate' of
http://www.linuxquestions.org/questi...-mysql-707427/

1) Acceptable answering time is usually said to be 48 hours.
2) Answering your own questions : Makes it look like an already
answered thread. Will no longer appear in "LQ zero reply".
When having further comments to your 'none answered' question,
please use the EDIT function instead.
..........

About your script : Why not change the syntax in line 10 ? ?

This will work different, and won't print 'syntax error'
Line 10 :
Code:

my $dbh = DBI->connect ( $driver, $database, "root" ) or die "cant connect to mysql";
Just guessing after a brief look here ( I am no coder )
http://search.cpan.org/~timb/DBI/DBI.pm
.....

To get around this
Quote:

DBD::Proxy : install_driver(Proxy) failed: Can't locate RPC/PlClient.pm in @INC
# cpan
cpan > install Net.Daemon RPC::PlClient
.....
P.S.: should have been 2 colons ( : ) between 'Net', 'Daemon',
can't write it, will display a 'smiley' instead.
....

knudfl 02-26-2009 11:27 AM

Sorry .........

haxpak 02-26-2009 11:09 PM

thanks to all of you
but i finally figred it out,
it was not mentioned anywhere just by chance
Code:

my $dsn = "dbi:mysql:project"
my $dbh = DBI->connect($dsn, "root", "") or die "cant connect to mysql";

i think
Code:

$ dbh = DBI->connect("$driver:$database", "root", "");
would also do the trick
so u see the ":" has to be inserted in the string.....

thanks all of u.

will come again if i face any other problem


All times are GMT -5. The time now is 06:35 AM.