LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-25-2009, 11:48 AM   #1
haxpak
Member
 
Registered: Jan 2009
Location: India
Distribution: fc9 x86_64
Posts: 35

Rep: Reputation: 15
Question 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
 
Old 02-25-2009, 12:29 PM   #2
haxpak
Member
 
Registered: Jan 2009
Location: India
Distribution: fc9 x86_64
Posts: 35

Original Poster
Rep: Reputation: 15
someone please reply
 
Old 02-25-2009, 01:58 PM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,519

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
'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.
....

Last edited by knudfl; 02-25-2009 at 02:03 PM.
 
Old 02-26-2009, 12:27 PM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,519

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Sorry .........

Last edited by knudfl; 02-26-2009 at 12:28 PM.
 
Old 02-27-2009, 12:09 AM   #5
haxpak
Member
 
Registered: Jan 2009
Location: India
Distribution: fc9 x86_64
Posts: 35

Original Poster
Rep: Reputation: 15
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl dbi module error "error at dbi:" dbi-> connect statement mysql haxpak Linux - Newbie 1 02-25-2009 09:22 AM
MySQL Perl DBI question GoTrolling Linux - Newbie 1 03-21-2007 05:31 AM
Mysql reading via Perl DBI ivanatora Programming 2 03-21-2007 05:03 AM
mysql + Perl (DBI) install problem tekmann33 Linux - Newbie 10 12-13-2006 06:38 PM
mysql failed: dbi error chadi Linux - General 1 10-30-2004 11:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration