2016-04-27 305 views
1

嗨在我的sql查询中我有这个错误有人可以帮我解决这个问题吗?非法混合的排序规则(utf8mb4_unicode_ci,IMPLICIT)和(utf8_general_ci,COERCIBLE)对于操作'like'

编辑:我添加了我的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); 
     } 
    }); 
}); 
+0

为什么在$的data数据字段中有'%' .ajax' – bugwheels94

+1

好点,谢谢我的问题解决。 – CHARLI

回答

0

$.ajaxdata字段中没有必要使用%,因为它可以在服务器端提供未知字符,因为该url将被视为已编码

相关问题