- 论坛徽章:
- 0
|
我的库建库到时候指定了CHARACTER set utf8
建表的时候也指定了CHARACTER SET UTF8
我是用perl程序把数据从xml里读出来
再插入到库里去的
解析xml用的是模块儿XML: arser
用DBI、DBD::mysql模块儿连的数据库
就是这样
require Encode;
use strict;
use DBI;
use XML: arser;
# create hash to hold values for expected column names
my %row = ("id" => undef, "value" => undef);
# connect to database and create parser object
my $dbh = DBI->connect ("DBI:mysql:test",
"root", "",
{ RaiseError => 1, PrintError => 0});
my $parser = new XML: arser (
Handlers => {
Start => &handle_start,
End => &handle_end,
Char => &handle_text
}
);
$dbh->do("SET NAMES utf8" ;
# parse file and disconnect
$parser->parsefile ("test.xml" ;
$dbh->disconnect ();
sub handle_start
{
my ($p, $tag) = @_; # parser, tag name
if ($tag eq "dv_address"
{
foreach my $key (keys (%row))
{
$row{$key} = undef;
}
}
}
sub handle_text
{
my ($p, $data) = @_; # parser, text
my $tag = $p->current_element ();
$row{$tag} .= $data if exists ($row{$tag});
}
sub handle_end
{
my ($p, $tag) = @_; # parser, tag name
if ($tag eq "row"
{
my $str;
# construct column assignments for INSERT statement
foreach my $key (keys (%row))
{
$str .= "," if $str;
$t = Encode::decode_utf8($dbh->quote($row{$key}));
$str .= "$key=" . Encode::encode("utf8", $t);
}
$dbh->do ("INSERT INTO test SET $str" ;
}
}
死活不成
乱码
远程ssh脸上去mysql看乱码
用程序php脸上去显示在页面上不论是用什么编码方式看都乱码
在php里作不做"set names utf8"的操作都乱码
[ 本帖最后由 foole 于 2005-11-17 15:23 编辑 ] |
|