Good day,
I am using Codeigniter to develop my webapp. PHP version on the server is 5.6.22 and Mysql version of the db is 5.6.27. In codeigniter's database.php when I change the charset to "utf8mb4" from "utf8", I get the following message .(image attached)
Unable to set client connection character set: utf8mb4
UPDATE I can run the codeigniter app on another server that has the same php version and the same mysql version. So it must be something pertaining to httpd.conf or php.ini, maybe?
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; For each column: ALTER TABLE table_name CHANGE column_name column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; (Don't blindly copy-paste this!
PHP UTF-8 Encoding – modifications to your php. The first thing you need to do is to modify your php. ini file to use UTF-8 as the default character set: default_charset = "utf-8"; (Note: You can subsequently use phpinfo() to verify that this has been set properly.)
utf-8 can store only 1, 2 or 3 bytes characters, while utf8mb4 can store 4 bytes characters as well. utf-8 is a subset of characters given by utf8mb4 .
In database.php
Set
char_set
toutf8mb4
anddbcollat
toutf8mb4_unicode_ci
orutf8_general_ci
I tested this with my 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 controller I add this
$CI = &get_instance();
$CI->load->database();
echo $CI->db->char_set;
echo "<br>";
echo $CI->db->dbcollat;
Output
utf8mb4
utf8mb4_unicode_ci
Read this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With