网站后台数据库转为Mysql,现在使用PERL连接数据库就方便多了。
通过DBI,PERL可以很容易的连接到数据库:
#!/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-> ";
}$dbh->disconnect();
执行结果:
[root@eygle ~]# PERL test.cgi
eygle