Mysql+php generated garbled reason:
MySQL database default encoding is UTF8, if this code and your PHP page is inconsistent, may cause MySQL garbled;
MySQL creates a table when you choose an encoding, if this encoding and your Web page encoding is inconsistent, may also cause MySQL garbled;
MySQL Create a table when you add a field can choose to encode, if this encoding and your Web page encoding inconsistent, may also cause MySQL garbled;
The user submits the page the code and displays the data the page code to be inconsistent, will certainly cause the PHP page garbled;
such as the user input data page is BIG5 code, display user Input page is gb2312, this 100% will cause PHP page garbled;
The PHP page character set is incorrect;
The PHP connection to the MySQL database statement specifies an incorrect encoding.
Attention:
Many people suspect that MySQL version inconsistency will lead to garbled, I believe that read this note you would not think so.
You may have several encodings of text you see on some sites, if you see a traditional characters, it may be BIG5 encoding, it may be utf-8 encoded, more likely to be GB code, yes, that is, there are simplified traditional Chinese characters, there is also a simplified Chinese code, we must understand this.
If you are doing a simplified code of the Web page, coding for GB2312, if the Hong Kong and Taiwan region of the visitors to submit traditional information, it may cause garbled, the solution:
Set the site code to Utf-8 so that all the characters in the world are compatible.
If the site has been operating for a long time, there are many old data, can not change the setting of Simplified Chinese, then it is recommended that the encoding of the page set to GBK, GBK and GB2312 is the difference between: GBK can display more characters than GB2312, to show the traditional character of simplified code, can only use GBK
Use mysql+php produce garbled reason all know very clearly, then solve is not difficult.
mysql+php to produce garbled solution:
If the installation of MySQL code can not be changed, many friends are buying a virtual host to build a Web site, do not have the right to change the installation of MySQL code, this can be skipped, because as long as the next step together correctly, the same can solve the garbled problem.
Modify the database encoding, if the database encoding is incorrect, you can execute the following command at phpMyAdmin:
ALTER DATABASE 'test' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
The above command is to set the test database encoding to UTF8.