简体   繁体   中英

my.ini and mysql_connect encoding

Does PHP's mysql_connect() function use the MySQL my.ini configuration file when it establishes the connection to the MySQL server instance? It seems not.

I have the table with the UTF-8 encoding and the PHP script which connects to the database and inserts data in UTF-8 encoding.

By default the mysql_client_encoding() returns latin1 . When I use mysql_query("SET NAMES utf8") or mysql_set_charset("utf8") after establishing the connecion, all works fine.

I would like to know is there other way to force use correct encoding for exchange data with MySQL from PHP?

I don't believe that there's any other way of defaulting the MySQL client encoding setting from the client side (with a php ini setting or similar).

From the server side you may find that the PHP client inherits the MySQL variable character_set_client but I'm unable to confirm that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM