perl dbi utf8 chinese

时间:2016-05-02 16:49:37

标签: perl dbi

这是我的perl程序在安装了ActiveState Perl的Windows 2003下运行,版本为v5.22.1。该脚本用于访问旧的Sybase Anywhere数据库版本6,Database charest = cp850。我的问题是如何正确显示汉字?任何提示解决这个问题?

xpathSApply(doc, "//TextBody", function(x) gsub("
", "\n", xmlValue(x) ))
[1] "First line.\nSecond line."

这是输出:

doc <- xmlParse("<a>test &quot; &apos; &lt; &gt; &amp;</a>")
xpathSApply(doc, "//a", xmlValue)
[1] "test \" ' < > &"

doc <- xmlParse("<a><![CDATA[test &quot; &apos; &lt; &gt; &amp;]]></a>")
xpathSApply(doc, "//a", xmlValue)
[1] "test &quot; &apos; &lt; &gt; &amp;"

以下是跟踪日志:

use utf8;
use DBI qw{:utils};
use strict;
use Encode;
use warnings;
use open ':utf8';

my $dbh = DBI->connect('DBI:ODBC:yfpy', 'dba', 'sql', { RaiseError => 1,        odbc_utf8_on => 1 }) 

    or die("\n\nCONNECT ERROR:\n\n$DBI::errstr");

my @rows = ();

my $sth = $dbh->prepare("SELECT custno, custsname, cname
                    FROM customer WHERE custno = 'ABC02' ORDER BY custno 
                    ");
$sth->execute() or die $DBI::errstr;

open FILE, '>:utf8', 'document.txt';

print FILE $dbh->{odbc_has_unicode};

print FILE "中文\n";

while (my @row = $sth->fetchrow_array()) {
   my ($custno, $name, $cname ) = @row;

print FILE "$custno\n";
print FILE "$cname\n";
print FILE "DBI describes data as: ", data_string_desc($cname), "\n";
}
$sth->finish();

close FILE;

B / R Gene Leung

0 个答案:

没有答案