perl连接数据库的写法

use DBI;  
my ($host, $user, $pwd, $db)=qw //;  
my $dbh = DBI->connect("DBI:mysql:database=$db;host=$host","user","pwd");  
my $sth = $dbh->prepare("select * from tablename where var=?");  
my $value = $sth->fetchrow() if $sth->execute($tid);  
my $sth->finish();  
$dbh->disconnect(); 

 

posted @ 2013-11-21 16:58  ops  阅读(405)  评论(0编辑  收藏  举报