zoukankan      html  css  js  c++  java
  • mysql dbi utf8乱码问题

    <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 "
    ";  
                                       }  
                           $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 "
    ";  
                                       }  
                           $dbh->disconnect; 
    jrhdpt02:/root/sbin# perl t1.pl 
    12123中均-至信30号250000011
    12222中均尊享-贰拾壹号5170000100003
    263180中均尊享-玖拾伍号2000000100003


    
                                        
    
  • 相关阅读:
    Python爬虫之Scrapy框架的简介和基础应用
    python爬虫之selenium,谷歌无头浏览器
    12.块设备驱动程序(磁盘)
    11.USB输入子系统
    10.触摸屏驱动
    9.LCD驱动架构
    8.platform驱动分离
    7.输入子系统框架
    5.标签管理
    4.分支管理
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351273.html
Copyright © 2011-2022 走看看