About the MySQL database encoding

Source: Internet
Author: User

Today, the data is submitted to PHP through the form and then inserted into the database. Web page and PHP encoding format are utf-8, when inserted into the database is also set $this->query ("Set names UTF8;");

However, there is a case of reading data garbled and question marks in MySQL. Later, it is no solution, the MySQL set to GBK encoding, incredibly can be displayed correctly, is simply to subvert the three views. So far I don't know why.

But in this process also learned some knowledge about coding:

Set the MySQL encoding in MySQL by modifying the configuration file My.ini, which is under the installation path of MySQL.

[MySQL//client

Default-character-set=utf8

[MYSQLD]//server side

Character-set-server=utf8

operate under the MySQL client:

Show VARIABLES like ' character% '; view Character set

SHOW VARIABLES like ' collation_% ';

The way to solve garbled characters is to set the following MySQL three system parameters to the same character set as the server character set character-set-server before executing the SQL statement.
Character_set_client: The character set of the client.
Character_set_results: Result character Set.
Character_set_connection: The connection character set.
Set the three system parameters by sending a statement to MySQL: Set names UTF8
This is done in PHP: mysql_query ("Set names UTF8");

About the MySQL database encoding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.