沃梦达 / 编程问答 / php问题 / 正文

php mysql SET NAMES 'utf8' COLLATE 'utf8_unicode_

php mysql SET NAMES #39;utf8#39; COLLATE #39;utf8_unicode_ci#39; doesn#39;t work with mysqli(php mysql SET NAMES utf8 COLLATE utf8_unicode_ci 不适用于 mysqli)

本文介绍了php mysql SET NAMES 'utf8' COLLATE 'utf8_unicode_ci' 不适用于 mysqli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的网站从 php mysql_* 方法迁移到 php mysqli.

I am migrating my site into php mysqli from php mysql_* methods.

我有以下代码来完成这项工作:

I had following code that did the job:

mysql_query("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'");

mysql_query("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'");

如果没有这个查询,我的字符串字符(格鲁吉亚语)是用问号写的.例如它被写成?????????而不是გამარჯობა

Without this query my string characters (in Georgian language) were written with question marks. For example it was written ????????? instead of გამარჯობა

所以既然它完成了它的工作,我很高兴,但现在我不能用 mysqli 做同样的事情.

So since it did its job I was happy, but now I cannot do the same with mysqli.

$mysqli = new mysqli("localhost", "root", "", "test");
$mysqli->query("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'");

谁能帮帮我?谢谢.

推荐答案

不建议使用 mysqli 查询来设置名称,而是使用 mysqli::set_charset

It is not recommended to use mysqli query in order to set names but rather mysqli::set_charset

$mysqli = new mysqli("localhost", "root", "", "test");
$mysqli->set_charset("utf8");

这篇关于php mysql SET NAMES 'utf8' COLLATE 'utf8_unicode_ci' 不适用于 mysqli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:php mysql SET NAMES 'utf8' COLLATE 'utf8_unicode_

基础教程推荐