假設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