假设Adams' Inn
America's Best Inn
存储在数据库表中establishment
我要检查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
。 文本编码为原文是什么。 我使用下面的DB经理:SQLyog的和PHPMyAdmin中。
更新#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()
现在。