September 2nd, 2000, 10:32 PM
Could anyone show me how may I connect from perl to mysql. Simple a piece of code will be enough. Thank you.
September 2nd, 2000, 11:52 PM
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;
or die "Couldn't execute statement: " . $sth->errstr;
while (@data = $sth->fetchrow_array())
$field1 = $data;
$field2 = $data;
[This message has been edited by RyanP (edited September 02, 2000).]
September 3rd, 2000, 09:29 PM
September 3rd, 2000, 10:40 PM
Don't worry about DBD:mysql. DBI is all you need.
September 4th, 2000, 01:08 AM
One more problem .
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.
September 4th, 2000, 11:37 AM
are you using ActivePerl? if so, then you should probably use their /bin/ppm to automatically download and install DBI