[英]MySQLiQuery_Exception' with message 'Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) - with PHP5
[英]Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like'
您好我的SQL查詢我有這個錯誤有人可以幫助我如何解決這個問題?
編輯:我添加了我的JavaScript代碼我認為問題是我的JavaScript代碼,因為當我直接使用我的PHP代碼而不發送post方法它的工作,但與JavaScript我有這樣的問題。
錯誤:
Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like' [1267]
An sql error occurred while fetching this page. Please contact an administrator if this problem persists
表
CREATE TABLE IF NOT EXISTS `core_members` (
`member_id` mediumint(8) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
PRIMARY KEY (`member_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
PHP:
@$key = $_POST['key'];
$result = $db->sql_query("SELECT member_id, name FROM core_members WHERE name LIKE '%{$key}%' LIMIT 10");
while ($row = $db->sql_fetchrow($result)) {
....
}
$db->sql_close();
JS:
$('#typeahead').keyup(function() {
if (this.value.length < 4) return;
var searchField = $('input.typeahead').val();
$.ajax({
type: "POST",
url: "./_api.php",
data: 'mod=searchFF&key=%' + searchField,
success: function(data) {
$(".tt-suggestions").html(data);
}
});
});
$.ajax
的data
字段中不需要%
,因為它可以在服務器端提供未知字符,因為該URL將被視為已編碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.