2016-04-27 35 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將被視爲已編碼

相關問題