問題描述
我正在使用 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 設置字符集的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!