yadianna 发表于 2017-5-17 09:59:05

Perl 链接数据库

#!/bin/perl
# 使用PERL的DBI连接MySQL数据库
use DBI;
#Connection to target DB
my $db_handle = DBI->connect("DBI:mysql:database=dbTest;host=localhost","username","password",{"RaiseError"=>1});
# Insert one row
my $rows = $db_handle->do("insert into mytable (`id`,`username`) values ('1','User_1_sosgoo')");
# Query
my $sqr=$db_handle->prepare("select * from mytable");
$sqr->execute();
while (my $ref=$sqr->fetchrow_hashref()){
print "$ref->{'username'}\n";
}
页: [1]
查看完整版本: Perl 链接数据库