The following query in MySQL as well as Codeigniter gives me an error.
SELECT * FROM table where name='hellome� test'
Error:
#1267 - Illegal mix of collations (latin1_swedish_ci,IMPLICIT)
and (utf8mb4_general_ci,COERCIBLE) for operation '='
This error also comes in Codeigniter.
Question
How to allow this type of characters in MySQL query.
You should set the database character encoding, inside the config > database.php as bellow. "utf8" is your db character encoding.
$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
);
use active records.
$this->db->select('*');
$this->db->from('blogs');
$this->db->where('name','hellome� test');
This is most likely as your table and database schema are in latin. Try running these commands:
ALTER DATABASE db CHARACTER SET utf8 COLLATE utf8_general_ci
ALTER TABLE table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.