开发者

Mysql SET NAMES UTF8 - how to get rid of?

In a very busy PHP script we have a call at the beginning to "Set names utf8" which is setting the character set in which mysql should interpret and send the data back from the server to the client.

http://dev.mysql.com/doc/refman/5.0/en/charset-applications.html

I want to get rid of it so I set default-character-set=utf8 In our server ini file. (see link above)

The setting seems to be working since the relevant server parameters are : 'character_set_client', 'utf8' 'character_set_connection', 'utf8' 'character_set_database', 'latin1' 'character_set_filesystem', 'binary' 'character_set_results', 'utf8' 'character_set_server', 'latin1' 'character_set_system', 'utf8' But after this change and commenting out set names utf8 call still the data starts to 开发者_开发百科come out garbled.

Please advise....


Setting the encoding of the connection between PHP and MySQL is PHP's job; I don't think the MySQL setting will affect that.

I'd really recommend keeping some code in the application to set the connection character set to UTF-8. The application needs to ensure that the encoding is UTF-8, because it will presumably be telling web browsers its pages are UTF-8, and if those don't match you've got problems.

Since it's already part of the application's responsibility to decide the charset, you might as well make the application the one to specify the database connection character set, rather than leave it as a deployment issue and one more thing to get wrong when installing the app on a new server.

However I would personally use mysql_set_charset to do this rather than SET NAMES.

Similarly, if the application has code in it to create the schema, make sure that code tells MySQL to make the tables UTF-8, rather than leaving it up to the database's default settings and giving yourself another deployment issue to worry about.


skip-character-set-client-handshake

but I don't think that Set names query is too much job. You've got your problem out of nowhere. And going to limit your database functionality

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜