When php reads and writes mysql data, garbled characters are usually caused by inconsistent database encoding, database table encoding, database table field encoding, and PHP output page encoding. You can refer to the solution described in this article. This article uses UTF-8 encoding example: 1. First, make sure that the mysql connection statement contains: mysql_query(“SET NAMES ‘utf8′”);mysql_query(“SET CHARACTER_SET_CLIENT=utf8″);mysql_query(“SET CHARACTER_SET_RESULTS=utf8″); The complete connection code is as follows: $host=”localhost”;$user=”root”;$pwd=”root”;$dbname=”wordpress”;$link = mysql_connect($host, $user, $pwd)or die(“Could not connect: ” . mysql_error());mysql_select_db($dbname, $link) or die (‘Can’t use wordpress : ‘ . mysql_error());mysql_query(“SET NAMES ‘utf8′”);mysql_query(“SET CHARACTER_SET_CLIENT=utf8″);mysql_query(“SET CHARACTER_SET_RESULTS=utf8″); 2. check whether the database encoding, database table encoding, database field encoding, and page encoding are consistent. 3, if there is still garbled, please check the php file encoding, you can save the file, when saving select UTF-8 encoding. |