網(wǎng)站后臺數(shù)據(jù)庫轉(zhuǎn)為Mysql,現(xiàn)在使用Perl連接數(shù)據(jù)庫就方便多了。
通過DBI,Perl可以很容易的連接到數(shù)據(jù)庫:
#!/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();
執(zhí)行結(jié)果:
[root@eygle ~]# perl test.cgi
eygle
微信搜索"考試吧"了解更多考試資訊、下載備考資料
相關(guān)推薦:
北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |