Wednesday, February 3, 2010

Perl connectivity with MySql using DBI

Install perl DBI using Perl Package Manager(PPM) using internet.

This is the simple program.

#!c:/Perl/bin/perl.exe
# PERL MODULES WE WILL BE USING
use DBI;
print "Content-type:text/html\n\n";

$dbh = DBI->connect('dbi:mysql:jsp','root','paasowrd')or die "Connection Error: $DBI::errstr\n";
$sql = "select * from users";
$sth = $dbh->prepare($sql);
$sth->execute
or die "SQL Error: $DBI::errstr\n";
while (@row = $sth->fetchrow_array) {
print "@row\n";
}



1 comment: