本文以UTF-8编码举例:
1、首先,确保mysql连接语句中包含:
mysql_query(“SET NAMES ‘utf8′”); mysql_query(“SET CHARACTER_SET_CLIENT=utf8″); mysql_query(“SET CHARACTER_SET_RESULTS=utf8″);
完整连接代码如下:
$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、检查数据库编码、数据库表编码、数据库字段编码、页面编码是否一致