error with national letters

error with national letters

zhirkov.ivanzhirkov.ivan Posts: 3Questions: 2Answers: 0
edited July 2015 in Free community support

if in table have DATETIME column
and iam try filtering by national (no english) letters
next i see error in any examples at Datatables:

"DataTables warning: table id=example - An SQL error occurred: SQLSTATE[HY000]: General error: 1271 Illegal mix of collations for operation 'like'"

but if iam writing directly SQL query in PHP - i never see this error in any national chars

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    This is not a DataTables error. You need to examine your database's tables for consistency of collation. You are probably querying two tables which do not have the same collation.

  • zhirkov.ivanzhirkov.ivan Posts: 3Questions: 2Answers: 0

    iam querying one table from example
    iam make this table in MySQL
    scheme db have a default collation utf8mb4_general_ci

    table i am making from example mysql.sql and using example code from http://datatables.net/examples/server_side/simple.html

    i think it really problem in collation but now i am not understand

  • allanallan Posts: 63,704Questions: 1Answers: 10,502 Site admin

    You might need to do something like SET NAMES 'utf8'; immediately after the database connection has been setup to ensure everything is consistent.

    Allan

  • GeneraleGenerale Posts: 4Questions: 1Answers: 0
    edited August 2015

    First of all, thanks a lot for this amazing plugin!
    Sorry for my poor English, but maybe it will help.
    I had same issue, and searching for any help I found this topic: http://stackoverflow.com/questions/10379299/operator-like-field-type-timestamp-and-cyrillic-mysql-bug
    Looks like there is MySQL bug, and you should try to convert your columns to UTF-8 string in ssp.class.php (filter function):

        static function filter ( $request, $columns, &$bindings )
        {
            $globalSearch = array();
            $columnSearch = array();
            $dtColumns = self::pluck( $columns, 'dt' );
    
            if ( isset($request['search']) && $request['search']['value'] != '' ) {
                $str = $request['search']['value'];
    
                for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) {
                    $requestColumn = $request['columns'][$i];
                    $columnIdx = array_search( $requestColumn['data'], $dtColumns );
                    $column = $columns[ $columnIdx ];
    
                    if ( $requestColumn['searchable'] == 'true' ) {
                        $binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
                        $globalSearch[] = "CONVERT(`".$column['db']."` USING utf8) LIKE ".$binding;
                    }
                }
            }
    

    Maybe it's not best solution, but i solve my problem.
    But I have another problem. Using this, I can't search date. When I try, I got "No matching records found".

This discussion has been closed.