使用MySQLi设置字符集 [英] Set character set using 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'");
从手册中:
From the manual:
这是更改字符集的首选方法.使用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驱动程序为您完成任务.
$mysqli->set_charset("utf8");
is just enough, let the mysqli db driver do the thing for you.
这篇关于使用MySQLi设置字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!