Home > Article > Backend Development > How to solve mysql garbled code in php?
Solution to mysql garbled characters in php:
Add SET NAMES UTF8 after mysql_connect to eliminate garbled characters in 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'");
The database character set is utf-8
Use this for the connection statement:
mysql_query("SET NAMES 'UTF8'"); mysql_query("SET CHARACTER SET UTF8"); mysql_query("SET CHARACTER_SET_RESULTS=UTF8'");
Recommended tutorial: "php tutorial》
The above is the detailed content of How to solve mysql garbled code in php?. For more information, please follow other related articles on the PHP Chinese website!