Solution to PHP reading MYSQL Chinese garbled characters_PHP tutorial

WBOY
Release: 2016-07-21 15:58:28
Original
704 people have browsed it

I was planning to switch the host of a website, but I didn't expect to encounter the problem of garbled Chinese characters in Php and Mysql.

The Mysql used by the foreign host in the past was the 4.x series. It felt relatively good. There was no garbled code in both GBK and UTF-8. I didn’t expect that the Mysql of the new host was version 5.0. Importing data Finally, when I read it with Php, it was full of question marks and garbled characters. I remember that I once had the experience of garbled characters when switching. The reason must be the difference between Mysql versions.

I had to check the information and found a solution, which is to add SET NAMES UTF8 after mysql_connect to eliminate garbled characters in the UTF8 database. For GBK database, use SET NAMES GBK. The code is as follows:

$mysql_mylink = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_query("SET NAMES 'GBK'");

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317594.htmlTechArticleI was planning to switch the host of a website, but I didn’t expect to encounter the problem of garbled Chinese characters in Php and Mysql. The Mysql used by foreign hosts in the past was the 4.x series, which seemed to be relatively good, regardless of GBK or UTF-8...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!