PHP connection MySQL database Chinese garbled solution _php Tutorial

Source: Internet
Author: User
PHP connection MySQL database garbled is usually the Chinese characters will be there, the English will not appear, because the MySQL default connection for UTF8, if your page and database encoding is not uniform, it is possible garbled.

Solutions

The page is gb2312

The code is as follows Copy Code

Mysql_qurey the decoding of the specified database to "set names gb2312" is to prevent Chinese garbled.

Page encoded as Uft8

The code is as follows Copy Code

mysql_query (' Set NAMES UTF8 ');//Set link encoding according to PHP file encoding

Cases

The code is as follows Copy Code

$connection =mysql_connect ($localhost, $username, $password);
mysql_query (' Set NAMES UTF8 ');//Set link encoding according to PHP file encoding
GBK words
mysql_query (' SET NAMES gbk ');
$db _selected = mysql_select_db ($database, $connection);
if (! $db _selected) {
Die (' Can ' t use DB: '. mysql_error ());
}

This can solve the output data will not be garbled, if you save the data garbled people as far as possible, the page encoding and database field encoding consistent can be resolved.

http://www.bkjia.com/PHPjc/632172.html www.bkjia.com true http://www.bkjia.com/PHPjc/632172.html techarticle PHP Connection MySQL database garbled is usually the Chinese characters will be there, the English will not appear, because the MySQL default connection is UTF8, if your page and database encoding is not uniform, it is possible ...

  • 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.