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

PHP shows that the garbled database encountered is mysql

巴扎黑
巴扎黑Original
2016-11-10 09:32:381295browse

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


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