In database.php
Set char_set to utf8mb4 and dbcollat to utf8mb4_unicode_ci or utf8_general_ci
I tested this with Codeigniter 3.0
$db['default'] = array( 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8mb4', 'dbcollat' => 'utf8mb4_unicode_ci', );
And in the controller I add this
$CI = &get_instance(); $CI->load->database(); echo $CI->db->char_set; echo "<br>"; echo $CI->db->dbcollat;
Exit
utf8mb4 utf8mb4_unicode_ci
Read it
- Using utf8mb4 with php and mysql
Abdulla nilam
source share