假设Adams’ Inn
America’s Best Inn
存储在数据库表establishment
mysqli的预处理语句不能读取的unicode
我要检查Adams’ Inn
America’s Best Inn
在一个变量$EstablishmentName
$stmt = $sql->prepare("SELECT ID FROM `establishment` WHERE Name=? LIMIT 1");
$stmt->bind_param("s",$EstablishmentName);
$stmt->execute();
$stmt->store_result();
print $stmt->num_rows;
问题是我无法找到他们。
输出0
注意封闭$EstablishmentName
与mb_convert_string($EstablishmentName,'HTML-ENTITIES')
否则你会用错误最终Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
更新:我用set_charset('utf8')
为客户端;表字符集是utf8,排序规则是utf8_general_ci
。文本被编码为原始文本。我正在使用以下数据库管理器:SQLyog和PHPMyAdmin。
UPDATE#2:我附上了截图给你看,我说的是正确的字符集。
我用$sql->set_charset('utf-8');
Array ( [BrandName] => America's Best Value Inn [try1] => 1 ) Array ( [BrandName] => Adams' Inn [try1] => 0 ) Array ( [BrandName] => Ambassador Inn and Suites [try1] => 1 ) Array ( [BrandName] => Amberley Suite Hotel [try1] => 1 ) Array ( [BrandName] => America's Best Value Inn [try1] => 0 )
更新#3好了,对不起。 Name
列是latin1_swedish_ci
。
我已经更新了列Name
:
ALTER TABLE establishment MODIFY NAME VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci;
这应该没有mb_convert_string()
现在的工作。
所以你的数据库连接的字符集是什么?你餐桌上的字符集?你提到htmlentities ...那么'''存储为编码实体?原始文本?没有更多细节,你的问题就无法得到解答。 – 2013-02-16 08:30:19
这两个文本都被编码为原始文本。我为客户端提供了set_charset('utf8'),表字符集是utf8,排序规则是utf8_general_ci。 – 2013-02-16 08:31:48
@MarcB你对此有何想法? – 2013-02-16 09:02:10