A quick solution to read Chinese garbled characters in MYSQL using PHP

高洛峰
Release: 2023-03-03 18:12:01
Original
1375 people have browsed it

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

The Mysql used by the previous foreign host 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. After importing the data, I used Php The words read out are all 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'");
Copy after login

The above is the entire content of the quick solution for reading MYSQL Chinese garbled characters in PHP brought to you by the editor. I hope it will be helpful to everyone. Please support the PHP Chinese website~

More quick solutions to reading MYSQL Chinese garbled characters with PHP For related articles, please pay attention to the PHP Chinese website!

Related labels:
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
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!