仍然有点疑惑,到底要怎么个插入法。又G了一通,在 http://yanfeng.org/blog/585/里找到了答案。Character set issues affect data storage, but also communication betweenclient programs and the MySQL server. If you want the client program tocommunicate with the server using a character set different from the default,you'll need to indicate which one. For example, to use the
utf8
Unicode character set, issue this statement after connecting to the server:SET NAMES'utf8';
看了这么一大堆,其实就是一句话,在调用mysql_connect()之后,再加上一句MySQL 4.1的字符集支持(Character Set Support)有两个方面:字符集(Character set)和排序方式(Collation)。对于字符集的支持细化到四个层次:服务器(server),数据库(database),数据表(table)和连接(connection)。当我们按照原来的方式通过PHP存取MySQL数据库时,就算设置了表的默认字符集为utf8并且通过UTF-8编码发送查询,你会发现存入数据库的仍然是乱码。问题就出在这个connection连接层上。解决方法是在发送查询前执行一下下面这句:SET NAMES‘utf8′;
為著解決這個問題必須去修改wp-includes/wp-db.php內的資料連線設定。詳細的修改方式是這樣的:$this->dbh =
@mysql_connect($dbhost,$dbuser,$dbpassword);
//加上下面這行$this->query("SET NAMES'utf8'");
mysql_query("SET NAMES'gb2312'")即可。前面所引用的例子是用了个handler来进行调用,而我只是在自己function里直接调用这个函数了。