2005-09-13 Perl与数据库DBI快速入门
1 基本流程 ##
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh = DBI->connect("DBI:mysql:test:192.168.1.2", 'root', 'password');
my $sth = $dbh->prepare("SELECT * FROM test1");
$sth->execute();
while ( my @row = $sth->fetchrow_array() )
{
print join('\t', @row)."\n";
}
$sth->finish();
$dbh->disconnect();1.1 连接数据库 ###
1.2 执行SQL语句 ###
1.2.1 技巧:对SQL进行排版 ####
1.2.2 通过SQL语句中的参数优化查询执行效率 ####
1.3 读取记录 ###
1.3.1 fetchrow_array ####
1.3.2 fetchrow_arrayref ####
1.3.3 fetchrow_hashref ####
1.4 结束一个SQL会话 ###
1.5 断开数据库连接 ###
2 参考资源 ##
最后更新于