Perl对Mysql的操作。
一、标准操作
1、连接、关闭
my $dbh = DBI->connect(”DBI:mysql:database=DBname;host=localhost”,”user”,”pwd”, {’RaiseError’ => 1});
… …
$dbh->disconnect();
2、类似插入等无返回操作
my $sqr = $dbh->prepare(”insert into table_name(Name,region_id,inuse,url) values (’”.$r_name.”‘,’”.($t+1).”‘,’1′,’”.$r_url.”‘) “);
$sqr->execute();
3、取得自增长的ID
执行插入操作后
my $table_key = $dbh->{’mysql_insertid’};
4、Select操作
my $row;
while ($row = $sqr->fetchrow_arrayref) {
printf $row->[0].”++”.$row->[1].”/n”;
}