简体   繁体   English

my.ini和mysql_connect编码

[英]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? 当PHP的mysql_connect()函数建立与MySQL服务器实例的连接时,是否使用MySQL my.ini配置文件? 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. 我有带UTF-8编码的表和连接到数据库并以UTF-8编码插入数据的PHP脚本。

By default the mysql_client_encoding() returns latin1 . 默认情况下, mysql_client_encoding()返回latin1 When I use mysql_query("SET NAMES utf8") or mysql_set_charset("utf8") after establishing the connecion, all works fine. 建立连接后,当我使用mysql_query("SET NAMES utf8")mysql_set_charset("utf8") ,一切正常。

I would like to know is there other way to force use correct encoding for exchange data with MySQL from PHP? 我想知道还有其他方法可以强制使用正确的编码与PHP中的MySQL交换数据吗?

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). 我不认为还有其他方法可以从客户端默认MySQL客户端编码设置(使用php ini设置或类似设置)。

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. 从服务器端,您可能会发现PHP客户端继承了MySQL变量character_set_client但我无法确认这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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