LoRz

Tuesday, June 17, 2008

 

Unable to set database connection charset: utf8 in CodeIgniter


If you have experiencing this error in CodeIgniter using CodeIgniter 1.6.x and MySQL 4.0


Unable to set database connection charset: utf8

It is setting the character set and collation for the database to which you are connecting.

A quick and dirty way of fixing this is looking for the db_set_charset() function on your system/database/drivers/your_driver/your_driver_driver.php

function db_set_charset($charset, $collation)
{
return TRUE;
//return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);
}

A better fix


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);
}
}


Set the following in your database.php

$db['default']['char_set'] = false;
$db['default']['dbcollat'] = false;





<< Home

Archives

June 2008   July 2008   August 2008   September 2008   October 2008   November 2008   December 2008   January 2009   February 2009   March 2009   May 2009   July 2009   September 2009   October 2009   WEC 44 live stream   UFC 106 live stream

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]