Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 12 revisions

When attempting to connect to or use MySQL 4.0 or below as a database with CodeIgniter 1.6 and above, you'll need to make the following adjustments, as there is a compatibility issue.

First a bit of an explanation: CI 1.6 now uses a feature of MySQL 4.1> called character sets and collation. These are not supported in MySQL 4.0 and below. Well, they are supported, just not in the same fashion as 4.1 and above.

If you attempt to connect to a MySQL 4.0 DB, you'll get this error: [quote] *An Error Was Encountered *Unable to set client connection character set: utf8 [/quote]

If you look at CI 1.6's database.php (system/application/config/) you'll see two new lines of code at the bottom of the DB config block: [code] $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci"; [/code]

These are used to set the character set and collation for the database to which you are connecting.

This is the adjustment you'll need to (temporarily) make to achieve a connection: Open up system/database/drivers/your_driver/your_driver_driver.php Find the db_set_charset() function, in the MySQL driver this is around line 95. Change it to say: [code] function db_set_charset($charset, $collation) { return TRUE; } [/code] I'd just comment out the existing line, as this is a somewhat temporary fix.

Test your connection -- you should be good to go.

See this forum post for more clarification: http://codeigniter.com/forums/viewthread/70698/

A final note -- If at all possible, get away from archaic MySQL 4.0, as it was be no longer supported my

Clone this wiki locally