|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Hi all!
Could anyone show me how may I connect from perl to mysql. Simple a piece of code will be enough. Thank you. ------------------ ___ Tim |
|
#2
|
|||
|
|||
|
hehe, there's a little more to it than that
do you have DBI and DBD:mysql installed? if so, check out the DBI documentation that came with your source to find examples of using the module your code will look something like this <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>use DBI; $dbh = DBI->connect('DBI:mysql:dbName') or die "Couldn't connect to database: " . DBI->errstr; $sth = $dbh->prepare('SELECT * FROM tableName') or die "Couldn't prepare statement: " . $dbh->errstr; $sth->execute() or die "Couldn't execute statement: " . $sth->errstr; while (@data = $sth->fetchrow_array()) { $field1 = $data[0]; $field2 = $data[1]; } $sth->finish; $dbh->disconnect;[/code] [This message has been edited by RyanP (edited September 02, 2000).] |
|
#3
|
|||
|
|||
|
Thank's for explanations.
I found DBI module at www.perl.com/CPAN-local/modules/by-module/ but not found DBD:mysql. Where I can find it? Do you know? ------------------ ___ Tim |
|
#4
|
|||
|
|||
|
Don't worry about DBD:mysql. DBI is all you need.
|
|
#5
|
|||
|
|||
|
One more problem URL.
I'm on WinNT. I unpacked the DBI archive, if I simple copy DBI.pm into perl/lib directory apache rase the error on "use DBI" line in CGI script. Can't find loadable module for DBI.pm line... Shall I first build anything how indexed in readme file? Other instruction I found say that it doesn't nessesary on WinNT. Thouth I tryed to build it. Command: "perl Makefile.PL" passed and create "makefile." file, but commnad: "make" rase an error. Did you install this module on WinNT or do you know anyone who did it? May be there is a ready to use DBI.pm module for WinNT? I'm in misunderstandings. ------------------ ___ Tim |
|
#6
|
|||
|
|||
|
are you using ActivePerl? if so, then you should probably use their /bin/ppm to automatically download and install DBI
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > connect to mysql |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|