商标符号在MySQL Select Query中不起作用

时间:2017-01-20 08:09:54

标签: php mysql codeigniter

MySQL和Codeigniter中的以下查询给出了错误。

SELECT * FROM table where name='hellome� test'

错误:

#1267 - Illegal mix of collations (latin1_swedish_ci,IMPLICIT) 
        and (utf8mb4_general_ci,COERCIBLE) for operation '=' 

此错误也出现在Codeigniter中。

问题

如何在MySQL查询中允许这种类型的字符。

3 个答案:

答案 0 :(得分:0)

您应该在config>内设置数据库字符编码。 database.php如下。 " UTF8"是你的数据库字符编码。

    $db ['default'] = array (
            'dsn' => '',
            'hostname' => 'localhost',
            'username' => '',
            'password' => '',
            'database' => '',
            'dbdriver' => 'mysqli',
            'dbprefix' => '',
            'pconnect' => FALSE,
            'db_debug' => (ENVIRONMENT !== 'production'),
            'cache_on' => FALSE,
            'cachedir' => '',
            'char_set' => 'utf8',
            'dbcollat' => 'utf8_general_ci',
            'swap_pre' => '',
            'encrypt' => FALSE,
            'compress' => FALSE,
            'stricton' => FALSE,
            'failover' => array (),
            'save_queries' => TRUE 
    );

答案 1 :(得分:0)

使用有效记录。

$this->db->select('*');
$this->db->from('blogs');
$this->db->where('name','hellome� test');

答案 2 :(得分:0)

这很可能是因为您的表和数据库架构是拉丁语。尝试运行这些命令:

  • ALTER DATABASE db CHARACTER SET utf8 COLLATE utf8_general_ci
  • ALTER TABLE table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci
相关问题