dbi 为总的接口,所有的库连接都使用他
根据不同的库选择不同的驱动dbd
#!c:\perl\binuse DBI;
my $host="127.0.0.1";
my $user="root";
my $db_name="sanshi";
my $pwd="";
my $con=DBI->connect("dbi:mysql:$db_name",$user,$pwd)
or die "can't connect to $dbname,$DBI::errstr";
print "Connect suc\n";
# my $query="select * from user";
my $query=qq(select * from user);
# my $query=q{select * from user};
my $result =$con->prepare($query) ||
die "Can't prepare statement: $DBI::errstr";
my $exec=$result->execute || die "Can't execute statement: $DBI::errstr";
while(($u_id,$u_name)=$result->fetchrow_array)
{
print "$u_id <--->$u_name\n";
}
$con->disconnect;