7

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

enter image description here

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?

3
  • did your change the charset of your database in actual. To do so Please read this mathiasbynens.be/notes/mysql-utf8mb4
    – Pradeep
    Commented Jul 14, 2016 at 13:13
  • Please see the update. Thanks
    – Waris Ali
    Commented Jul 15, 2016 at 11:49
  • I had the same problem while trying to run migrations (using CI4/PHP 8.2.10/MySQL 8.2.0) . I solved it by editing the file 'app\Config\Database.php' and changing 'charset' and 'DBCollat' to 'charset' => 'utf8mb4' and 'DBCollat' => 'utf8mb4_spanish_ci' Commented Dec 1, 2023 at 13:10

2 Answers 2

6

In database.php

Set char_set to utf8mb4 and dbcollat to utf8mb4_unicode_ci or utf8_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

  1. Using utf8mb4 with php and mysql
5
  • as i know there are nothing with the php.ini or my.ini(mysql) Commented Jul 15, 2016 at 11:57
  • Please see my updated question. Also I cannot test this in controller as it does not allow me to load view. Just give me the error as in screenshot.
    – Waris Ali
    Commented Jul 15, 2016 at 11:59
  • @WarisAli are you still facung this issue?? Commented Jul 19, 2016 at 1:43
  • No. Turns out although php5.5+ support utf8mb4, there are some versions that have some known issues with the char encoding of the type. I unistalled and installed the latest php and the error was gone. It was strange.
    – Waris Ali
    Commented Jul 19, 2016 at 6:52
  • @WarisAli I'm using php 7. That's what i inform you early Commented Jul 19, 2016 at 9:22
0

I was able to remove the bug by removing my php installation and installing the httpd and php again from scratch.

Not the answer you're looking for? Browse other questions tagged or ask your own question.