用PERL连接MYSQL
#!/bin/perl
use DBI;
# Connect to target DB
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost","username","password", {'RaiseError' => 1});
#lock table
$dbh->do("lock table test write");
# Insert one row
my $rows = $dbh->do("INSERT INTO test (id, name) VALUES (1, 'fire9')");
# query
my $sqr = $dbh->prepare("SELECT name FROM test");
$sqr->execute();
while(my $ref = $sqr->fetchrow_hashref()) {
print "$ref->{'name'}\n";
}
#unlock table
$dbh->do("unlock tables");
$dbh->disconnect();
阅读(475) | 评论(0) | 转发(0) |