Correct default encoding

Source: Internet
Author: User
Modify the default encoding. This code is really messy. When the database server is installed, no database code is selected. Query Database code PHPcodeshowcreatedatabaseguest; all are latin1. I searched Google and asked the following questions: 1: Can the default-character-set = gb2312 be changed globally? (Modify the default encoding.
This code is really messy.
When the database server is installed, no database code is selected. Query Database encoding
PHP code
  show create database guest;

All are latin1. Searched Google,
Have the following questions,
1: Can default-character-set = gb2312 be changed globally? (That is, modify the default character set of the database server)
2: latin1 by default. no encoding is specified during database creation. should latin be used at this time?
Php connects to the database. if I specify the encoding, how can this problem be solved?
PHP code
  mysql_query(set names gb2312)

It seems to be written like this. do not blame new users.

------ Solution --------------------
Default-character-set in my. ini is the default character set of mysql.
If this parameter is modified, restart mysql.
If the modification is made, the requirements of other users must be taken into account!

If this parameter is not modified, the character set is not involved in all mysql applications. This will return to the original database.

In fact, mysql introduces the character set concept, but there is no subsequent action. For example, full-text search is still unavailable

------ Solution --------------------
When creating a database, set it to the encoding you need, such as utf8 gbk.
Php is executed when operating the database.
Mysql_query ("SETNAMES utf8"); // or SETNAMES gbk

Specify the encoding for the output page when obtaining the dataset.

Header ("Content-type: text/html; charset = utf-8"); // or gbk

For UTF-8 file encoding, remember to save the corresponding encoding.

And so on...
///////////////////////////////////
Export your data, re-set the database encoding, and then import the data. then, refer to the above method for operations.

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.