mysqli准备的语句无法读取unicode [英] mysqli prepared statement cannot read unicode
问题描述
假定存储在数据库表establishment
我必须检查变量$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
注意用mb_convert_string($EstablishmentName,'HTML-ENTITIES')
括在$EstablishmentName
内,否则将出现错误Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
Note enclosed $EstablishmentName
with mb_convert_string($EstablishmentName,'HTML-ENTITIES')
else you'll end up with error 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: I use set_charset('utf8')
for the client side; the table charset is utf8, and collation is utf8_general_ci
. The text is encoded as what the original text is. I am using the following DB Manager: SQLyog and PHPMyAdmin.
更新#2::我已经附上了屏幕截图,以便您告诉我正确的字符集.
UPDATE #2: I have attached the screenshot for you to look that I am telling the correct charset.
我使用$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
:
UPDATE #3 Ok, sorry. The column Name
was latin1_swedish_ci
.
I have updated the column Name
:
ALTER TABLE establishment MODIFY NAME VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci;
这应该在没有mb_convert_string()
的情况下起作用.
This should work without the mb_convert_string()
now.
推荐答案
这解决了问题:
iconv('windows-1250', 'utf-8', $EstablishmentName);
这篇关于mysqli准备的语句无法读取unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!