1、查看系統上是否已經安裝好了DBI,perl -e "use DBI",如果沒有出現錯誤且沒有退出,表明已經安裝
此模塊。
2、如果未安裝,到
www.cpan.org進行下載兩個模塊,DBI-1.607.tar.gz和DBD-mysql-4.010進行安裝。
tar -xzvf DBI-1.607.tar.gz
cd DBI-1.607
perl Makefile.PL
make
make test
make install
DBD-myql-4.010也同樣的方式進行安裝。
3、通過下面的perl腳本連接數據庫:
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost","root","123456");
my $sth = $dbh->("select * from clients");
$sth->execute();
while(my $ref = $sth->fetchrow_hashref())
{
print "cid=$ref->{'cid'} and cname=$ref->{'cname'}\n";
}
$sth->finish();
$dbh->disconnect();