Home >Backend Development >PHP Tutorial >PHP shows that the garbled database encountered is mysql

PHP shows that the garbled database encountered is mysql

巴扎黑
巴扎黑Original
2016-12-07 15:31:091010browse

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'");

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'");

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


Statement:
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