6. Note: For this function to work on a Windows platform, you need MySQL client library 4.1.11 or above (for MySQL 5.0, you need 5.0.6 or above). 7. ref: 谈谈MySQL乱码和set names 我个人觉得,由于本地机为gbk编码,所以,即使创建数据库时的编码是utf8,当我们录入数据时,仍然需要告诉mysql,本地机器编码为gbk. The PHP manual explicitly warns us to use mysqli_set_charset , not SET NAMES : This is the preferred way to change the charset. Patricio wrote on 31st July 2012 at 02:36: Nice article Mathias, this also took me by surprise some time ago.
That’s all you need. I am using an INI file to save the adapter config data. Note: . So, when you type é, the client generates the 2 bytes C3 A9. Don’t rely on the server’s default values. ; Then those are sent as if they were latin1 to the server (mysqld). And use SET NAMES or mysql(i)_set_charset() in PHP or something similar after each connect to a MySQL server. Using mysql_query() to set it (such as SET NAMES utf8) is not recommended.See the MySQL character set concepts section for more information. set the 'names' (set names *) or _ANY_ 'character set' (set character set *) (opposed to what they tell you on these pages). mysql> set names utf32; Query OK, 0 rows affected (0.00 sec) mysql> select 5; ERROR 2013 (HY000): Lost connection to MySQL server during query mysql> [6 Dec 2007 7:48] Alexander Barkov . All char_sets here should say 'latin1', except for the system one which is always 'utf8'. Calling SET CHARACTER SET utf8 after SET NAMES utf8 actually just undoes some of the work that SET NAMES did. mysql_query("set names 'utf8'"); Note that you should write the encode which you are using in the header for example if you are using utf-8 you add it like this in the header or it will couse a problem with Internet Explorer
By executing "set names utf8", it sets the client character set variables to utf8. So the values sent from the client program are stored 'as is' in the table because the client character set and the table's character set is the same. Type '\c' to clear the buffer. what entries should I add there? This is FAQ.
I think this behavior and workaround should be documented somewhere in the manual. If it wasn't clear, I am looking for the correct syntax to do it in the config.ini file of my project and not in php code, as I regard this part of the configuration code. This is the preferred way to change the charset. Do *NOT* (repeat NOT!) ; The Server says "Oh, I am getting some latin1 bytes, and I will be putting them into a latin1 column, so I don't need to transform them.
This function requires MySQL 5.0.7 or later. Notes. 这样数据在 MySQL内部的存储表示 为 utf8 字符集,而 与 客户端交互时,使用gbk字符集合. mysql set names 问题 mysql_query("set names utf8");一直以来总以为set names 是用来设置msyql 的字符集的,最近作个东西才发现自己认识上的错误,查一下手册SET NAMES ‘x‘语句与这三个语句等价:mysql> SET character_set_client = x;mysql> SET mysql_query( ) で (SET NAMES utf8 などとして) 設定する方法はお勧めできません。 詳細は MySQL の文字セットの概念 を参照ください。 参考 mysql> set names utf32; Query OK, 0 rows affected (0.00 sec) mysql> select 5; ERROR 2013 (HY000): Lost connection to MySQL server during query mysql> [6 Dec 2007 7:48] Alexander Barkov . Check the previous item by listing the results of the mysql query 'SHOW session VARIABLES'. ; But (apparently) it is actually utf8. How to make PDO adapter run SET NAMES utf8 each time I connect, In ZendFramework. 1年くらい前に社内MLに投げた、「MySQLでSET NAMESを使ってはいけない理由」をコピペしてみます。手抜きです、はい。 赤字は注釈です。 今更ながら、「MySQLで SET NAMES を使ってはいけない」の根拠のお話です。 下記のPHPスクリプトでは、入力値を元にSQL文を生成し、検索クエリを投げて … SET NAMES latin1 declares that the encoding in your client is latin1.
The set_charset() / mysqli_set_charset() function specifies the default character set to be used when sending data to and from the database server.
Type '\c' to clear the buffer. Note: .