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_* 方法迁移到 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_
基础教程推荐
- 在多维数组中查找最大值 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01