通过使用DBI,用Perl可以很容易的连接到MysqL数据库:
代码如下:
代码如下:
#!/bin/perl
use DBI;
# Connect to target DB
my $dbh = DBI->connect("DBI:MysqL:database=eygle;host=localhost","username","password",{'RaiseError' => 1});
# Insert one row
my $rows = $dbh->do("INSERT INTO test (id,name) VALUES (1,'eygle')");
# query
my $sqr = $dbh->prepare("SELECT name FROM test");
$sqr->execute();
while(my $ref = $sqr->fetchrow_hashref()) {
print "$ref->{'name'}n";
}
$dbh->disconnect();
执行结果:
代码如下:
[root@eygle ~]# perl test.cgi
eygle
原文链接:https://www.f2er.com/php/24803.htmleygle