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