您的位置:首页 > 数据库 > MySQL

mysql dbi utf8乱码问题

2015-10-23 16:57 676 查看
<pre name="code" class="python">jrhdpt02:/root/sbin# cat t1.pl
#!/usr/bin/perl
use DBI;
$user="root";
$passwd="xxxxx";
$dbh="";
$dbh = DBI->connect("dbi:mysql:database=zjzc;host=127.0.0.1;port=3306",$user,$passwd) or die "can't connect to  database ". DBI-errstr;
#$dbh->do("SET NAMES utf8");
$sth=$dbh->prepare("select sn,duration,name,maxUnit,addUnit,productType from  zjzc.Product  where sn in (263,121,122);");
$sth->execute;
while (@recs=$sth->fetchrow_array) {
foreach (@recs)
{print "$_"}
print "\n";
}
$dbh->disconnect;
jrhdpt02:/root/sbin# perl t1.pl
12123??-??30?250000011
12222????-????5170000100003
263180????-????2000000100003

jrhdpt02:/root/sbin# cat t1.pl
#!/usr/bin/perl
use DBI;
$user="root";
$passwd="R00t,uHagt.0511";
$dbh="";
$dbh = DBI->connect("dbi:mysql:database=zjzc;host=127.0.0.1;port=3306",$user,$passwd) or die "can't connect to  database ". DBI-errstr;
$dbh->do("SET NAMES utf8");
$sth=$dbh->prepare("select sn,duration,name,maxUnit,addUnit,productType from  zjzc.Product  where sn in (263,121,122);");
$sth->execute;
while (@recs=$sth->fetchrow_array) {
foreach (@recs)
{print "$_"}
print "\n";
}
$dbh->disconnect;
jrhdpt02:/root/sbin# perl t1.pl
12123中均-至信30号250000011
12222中均尊享-贰拾壹号5170000100003
263180中均尊享-玖拾伍号2000000100003



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: