Set character set using MySQLi

前端 未结 5 1353
慢半拍i
慢半拍i 2020-11-29 04:57

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(\'SE         


        
5条回答
  •  生来不讨喜
    2020-11-29 05:36

    It's the same:

    $mysqli->query("SET NAMES 'utf8'");

    From the manual:

    This is the preferred way to change the charset. Using mysqli::query() to execute SET NAMES .. is not recommended.

    $mysqli->set_charset("utf8"); is just enough, let the mysqli db driver do the thing for you.

提交回复
热议问题