Set character set using MySQLi(使用 MySQLi 设置字符集)
问题描述
我正在使用 MySQLi 从 MySQL 表中获取阿拉伯语数据.所以我通常在程序风格中使用它:
I'm fetching data in Arabic from MySQL tables with MySQLi. So I usually use this in procedural style:
mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8');
现在我使用的是 OOP 风格,所以我想看看是否有我可以设置的东西而不是上面的东西?
Now I am using the OOP style so I am trying to see if there is something I could set rather than the above?
我只在 PHP 手册中找到了这个,所以我做了,但是将名称设置为 UTF8 怎么样?
I only found this in PHP manual so I did it, but what about setting names to UTF8?
$mysqli->set_charset("utf8");
推荐答案
都一样:
$mysqli->query("SET NAMES 'utf8'");
来自手册:
这是更改字符集的首选方法.使用 mysqli::query()不建议执行 SET NAMES ..
This is the preferred way to change the charset. Using mysqli::query() to execute SET NAMES .. is not recommended.
$mysqli->set_charset("utf8"); 就够了,让 mysqli db driver 为你做这件事.
$mysqli->set_charset("utf8"); is just enough, let the mysqli db driver do the thing for you.
这篇关于使用 MySQLi 设置字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 MySQLi 设置字符集
基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
