DB: mysql5.1
DB charset: UTF-8
开发语言: PHP
问题:
通过php mysqli连接到DB后, 删除数据, SQL的where条件的值中包含汉字.
例:
delete from keywordlist where userid='peter' and keyword='通信速度';
一直不能删除数据, 最后在PHP中追加了设定字符集后, 能正常删除了.
追加如下一行:
$mysqli->set_charset("utf8");
php文件内容:
connect_errno) { echo $callback.'({"result": "Database connect error!!"})'; return; } $mysqli->set_charset("utf8"); $sql = "delete from keywordlist where userid='" . $userid . "' and keyword='" . $mysqli->real_escape_string($keyword) ."'"; error_log("sql: ".$sql); $mysqli->query ( $sql ); $mysqli->close (); echo $callback.'({"result": "OK", "keyword": "'.$keyword.'", "sql": "'.$sql.'"})';