Mysql Encoding Problem
In the php page You can insert English characters into MySQL , but it is not possible to insert Chinese characters, in the cmd client can also be inserted from, this is a problem that bothers me for two days.
Find a lot of information on the Internet, finally determined that the character encoding this place has a problem, first of all, to the MySQL database through the PHP page to insert Chinese characters, you have to file encoding, code encoding and MySQL encoding is consistent, my current encoding is Utf-8 , the default encoding for the file is set to Utf-8 after that, you will also be in each PHP The page is prefixed with the header ("Content-type:text/html;charset=utf-8"), mysql_query ("Set names UTF8").
Next isMySQLencoding problem, but also to set the encoding toUtf-8, my version isWin7of the -bit ofmysql5.6Installation-free version, inMysql.iniof the[Mysqld]added incharacter_set_server = UTF8, never addDefault-character-set=utf-8, because it will lead to yourMySQLcannot be opened and then passedShow variables like'%char% ' to view the encoded settings,
Character_set_client,character_set_connection,character_set_database and character_set_results are all utf-8 , basically no problem.
But in order to avoid problems, we try to set up the database and the table when it is encoded, create theexists databasename default charset UTF8; and the CREATE table if not EXISTS table TableName (col type) default CharSet UTF8; Of course we can also modify his default code, modify the database encoding ALTER DATABASE databasename default CharSet UTF8; Modifying the encoding of a table ALTER TABLE tablename default CharSet UTF8, This basically does not appear can not insert Chinese characters, or inserted in the language after the display garbled.