SET NAMES utf8 in MySQL?

前端 未结 8 1300
北海茫月
北海茫月 2020-11-22 11:30

I often see something similar to this below in PHP scripts using MySQL

query(\"SET NAMES utf8\");   

I have never had to do this for any pr

相关标签:
8条回答
  • 2020-11-22 11:59

    Instead of doing this via an SQL query use the php function: mysqli::set_charset mysqli_set_charset

    Note:
    
    This is the preferred way to change the charset. Using mysqli_query() to set it (such as SET NAMES utf8) is not recommended.
    

    See the MySQL character set concepts section for more information.

    from http://www.php.net/manual/en/mysqli.set-charset.php

    0 讨论(0)
  • 2020-11-22 12:09

    Not only PDO. If sql answer like '????' symbols, preset of you charset (hope UTF-8) really recommended:

    if (!$mysqli->set_charset("utf8")) 
     { printf("Can't set utf8: %s\n", $mysqli->error); }
    

    or via procedure style mysqli_set_charset($db,"utf8")

    0 讨论(0)
提交回复
热议问题