PDA

View Full Version : connect to database and retrieve records



hongyi
09-13-2002, 08:17 AM
hi, everyone..

very new to perl. need help in knowing how to connect to mysql database and after which store the records in a array or something. it would help if u could teach me how to declare variables and display variables.

pls help asap...

FlashCoder
09-20-2002, 05:46 PM
This code connected to database:

#!/usr/bin/perl
use DBI;
print "Content-Type: text/html\n\n";

my $dbh = DBI->connect("DBI:mysql:DATABASE;HOST",LOGIN,PASSWORD);

$result = $dbh->prepare("SELECT * FROM meet ORDER BY id");
$result->execute();

and read example:

while (my $ln = $result->fetchrow_hashref())
{
print "$ln->{id}";
}

Ok?

--
Denis.
ICQ UIN: 150757646