SET NAMES utf8 in MySQL?

前端 未结 8 1473
北海茫月
北海茫月 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:56

    From the manual:

    SET NAMES indicates what character set the client will use to send SQL statements to the server.

    More elaborately, (and once again, gratuitously lifted from the manual):

    SET NAMES indicates what character set the client will use to send SQL statements to the server. Thus, SET NAMES 'cp1251' tells the server, “future incoming messages from this client are in character set cp1251.” It also specifies the character set that the server should use for sending results back to the client. (For example, it indicates what character set to use for column values if you use a SELECT statement.)

提交回复
热议问题