Understanding of Utf-8,utf8 (UTF8), set names GBK in Php+mysql

Source: Internet
Author: User
Tags php and mysql

Problem one: When we do the database operation, we will find that the table in the database is encoded with UTF-8, but the DOS command is to use set names GBK

(a) The default character set in MySQL is four levels: server level, database level, table level, and field level top three are the default settings, does not mean that your field will eventually use this character set

(ii) Set names this MySQL command setting is the command code issued by the client, the connection layer encoding, and the server side to return the results of the encoding, equivalent to the client and server interaction with the encoding, rather than the data saved encoding

Question two: When we use it, when we set names UTF, when we use the Select command to display the contents of the table, the Chinese will become garbled, while the GBK is normal

(a): Set names is used to set the PHP and MySQL communication character encoding, that is: PHP file encoding format is GBK or gb2312, when the data query, to set the MySQL communication encoding format is GBK

(b): UTF8 Do not import GBK, gbk do not import UTF8

(c): UTF8 display is not supported under DOS

The difference between UTF-8 and UTF8:

(a) First PHP is not case-sensitive in English, UTF-8 it is a standard notation, so it can be written utf-8

(b) UTF-8 can also be the middle of "-" omitted, written UTF8, general procedures can be recognized, but there are exceptions, so in order to strictly some, do the best of their own standard capitalization UTF-8

(c) In the database can only use "UTF8" (MySQL), in the MySQL command mode can only use "UTF8", Can not use "utf-8", that is, in the PHP program can only use "Set names UTF8 (no small bars)", if you add "-" This line command will not take effect, but the header in PHP to add "-", because IE does not know the "UTF8", for reasons see below.

Header in PHP: <?php header (' content-type:text/html; Charset=utf-8 ');?>

Strange: Content-tyep with a colon, but chatset is an equal sign.

Static file use: <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>

Summary: "Utf-8" can only be used in MySQL with the alias "UTF8", but in other places use uppercase "UTF-8". Specifically: Use uppercase "UTF-8" outside the Command "mysql_query (set names UTF8)".

Understanding of Utf-8,utf8 (UTF8), set names GBK in Php+mysql

Related Article

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.