-
Notifications
You must be signed in to change notification settings - Fork 0
MySQL 4.0
Core:Config::Database | Core:Help::TipsAndTricks
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:
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
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:
function db_set_charset($charset, $collation)
{
if($charset == false || $collation == false)
{
return true;
}
else
{
return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);
}
}
Then, in your database.php:
$db['default']['char_set'] = false;
$db['default']['dbcollat'] = false;
With this settings, CI keeps compatibility with any version of MySQL.
Test your connection -- you should be good to go.
See this forum post for more clarification.
One final note: If at all possible, move away or upgrade from mysql 4.0, as it is no longer supported by MySQL (since 2006) and after december 2008, will no longer receive security updates.
Lastly, according to a Codeigniter admin, there are other additional upcoming features that will require MySQL 4.1 and above.