Codeigniter does not accept "utf8mb4" as default encoding

Good day,

I am using Codeigniter to develop my webapp. The PHP version on the server is 5.6.22, and the Dys version for Mysql is 5.6.27. In codeigniter database.php, when I change the encoding to "utf8mb4" from "utf8", I get the following message (attached image)

Unable to set client connection character set: utf8mb4

enter image description here

UPDATE I can run the codeigniter application on another server that has the same php version and the same mysql version. So this should be something related to httpd.conf or php.ini, maybe?

+7
php mysql codeigniter utf-8
source share
2 answers

I managed to remove the error by uninstalling my php installation and installing httpd and php again from scratch.

0
source share

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
+2
source share

All Articles