Perl DBI 提供对宽字符串支持的接口:
use DBI qw(neat data_diff data_string_desc);
其中data_string_desc 可以查看一个字符串编码方式:
data_string_desc($str);#返回的信息描述可能是:
“
UTF8 off, ASCII, 42 characters 42 bytes
UTF8 off, non-ASCII, 42 characters 42 bytes
UTF8 on, non-ASCII, 4 characters 6 bytes
UTF8 on, non-ASCII, 2 characters 6 bytes #non-ASCII 表示字符串中有大于127的字符
UTF8 on but INVALID encoding, non-ASCII, 4 characters 6 bytes #表示字符串编码有问题,即utf8字符串中有其它编码字符
UTF8 off, undef
”
如想在dbi::do() 中支持Unicode 字符串,则需在connect时指定,
DBI->connect( "dbi:mysql:dbname=db_name", "db_user", "db_pass", {RaiseError => 0, mysql_enable_utf8 => 1} ) or die "Connect to database failed.";
阅读(676) | 评论(0) | 转发(0) |