mysql rpc_使用XML-RPC和MySQL处理中文字符

我有一个异步Web服务,移动应用的用户可以在他们的手机上发表评论,它使用JSON将帖子上传到API,服务器将帖子输入到数据库中,并将确认发送回设备。服务器使用XML-RPC传递消息,但与设备的所有通信均由JSON完成。

我现在试图添加对汉字的支持。当我从设备上发布帖子时,这是JSON文本发送时的外观:

Request object:

(

{

comment = "\U4e2d\U56fd";

"post_id" = 119791544;

}

)该评论值代表中国的两个汉字。当它被输入到数据库中时,它会以“??”的形式出现。看着这个十六进制值,它转换为3F3F,所以数据库绝对只是存储问号而不是在显示字符时遇到麻烦。这也意味着服务器明白只有两个字符可以通过,因此它可以识别正在进入的字符的大小。这是服务器从设备接收数据时调用的函数:

function server_impl_post_comment($m)

{

global $xmlrpcerruser;

$auth = server_utils_authenticate_client();

// return error if client is not authorised to use the api

if (!$auth['result'])

{

return new xmlrpcresp(0, $xmlrpcerruser, $auth['reason']);

}

logger_api_log_method_call('ff.post_comment', $auth['user_id']);

$args = $m->getParam( 0 );

$c['user_id'] = $auth['user_id'];

$c['post_id'] = $args->structmem( "post_id" )->scalarval();

$c['comment'] = $args->structmem( "comment" )->scalarval();

// @todo: chinese characters come through as ? here

// submit the comment

$comment = post_comment($c);

$post = post_get_post($c['post_id']);

$result = server_utils_format_result_struct(TRUE, POST_COMMENT_TITLE, POST_COMMENT_MSG, POST_COMMENT_BUTTON, POST_COMMENT_SHOW, $c['post_id'], $comment);

$result['post_info'] = server_utils_format_post_info($post);

$result['post_up_votes'] = $post['post_vote_up_count'];

$result['post_down_votes'] = $post['post_vote_down_count'];

$result['post_comments'] = $post['post_comment_count'];

return new xmlrpcresp(php_xmlrpc_encode($result));

}在@todo注释行我添加了一个日志记录方法,$ c ['comment']以“??”的形式出现再次。我尝试在开始时记录$ m的值,但由于某种原因,这并不起作用。在服务器上使用的XML-RPC库是Edd Dumbill的xmlrpc.inc v1.169,据我所知,它支持UTF-8。任何想法,哪里出错了?我已经能够用SQL直接插入中文字符到数据库中,所以它一定是正在发生的事情。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值