PHP shows that the garbled database encountered is mysql

巴扎黑
Release: 2023-03-03 12:30:02
Original
981 people have browsed it

I encountered the problem of garbled characters when using PHP+MYSQL. The solution:

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:

1 $mysql_mylink = mysql_connect($mysql_host, $mysql_user, $mysql_pass); 
2 mysql_query("SET NAMES 'GBK'");
Copy after login

The database character set is utf-8

Use this for the connection statement

1 mysql_query("SET NAMES 'UTF8'"); 
2 mysql_query("SETCHARACTERSET UTF8"); 
3 mysql_query("SET CHARACTER_SET_RESULTS=UTF8'");
Copy after login

The above is the content of PHP showing that the database is mysql when it encounters garbled characters. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


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
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!