[PerlChina] 停止/开始 Perl 脚本后台模式运行

Jeff Pang pangj at earthlink.net
Sat Oct 27 20:46:05 PDT 2007


On 10/28/07, Jesse Lee <cdrplum at gmail.com> wrote:
>有一个使用 Jabber 协议的聊天程序,通过客户端发送的信息存到 MySQL 数据库后中文文字变成了这样的:
> &#x4FE1;&#x606F;&#x592A;&#x77ED;
> 上面对应的是 "信息太短" 四个字,使用的都是 UTF8 编码,在网页上显示也是正常的,这样是否正常呢?
>  能否变成直接的中文?在 phpmyadmin 中看到中文?
>

Before inserting into database,you will add a set names statement:

$sth = $dbh->prepare("set names 'utf8'");
$sth->execute();

Also you'd better translate the values from gb* to utf-8 before inserting.

use Encode;
$cn_characters = "信息太短";
$cn_characters = encode("utf8",decode("gb2312",$cn_characters));

then in sql,

insert into table (cn_character_column) values ($cn_characters);


More information about the China-pm mailing list