[eluser]Jeffrey McManus[/eluser]
I'm trying to use CodeIgniter to display some unicode data stored in MySQL. I am able to successfully query and display the data using PHP/mysql but the unicode data does not display correctly when I query it using CodeIgniter.
Here is the SQL I used to create the table:
Code:
CREATE TABLE `languages` (
`id` char(2) NOT NULL DEFAULT '' COMMENT 'The ISO code for this language.',
`name` varchar(40) NOT NULL COMMENT 'The name of the language in English.',
`local_name` varchar(40) NOT NULL DEFAULT '' COMMENT 'The name of the language in that language',
`sequence` int(11) DEFAULT '0',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`modified` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Here is the code I used to successfully query and output data from the table using PHP/mysql:
Code:
if($cn = mysql_connect('localhost', 'xxxx', 'xxxx')) {
echo "Connected to db.<br />";
} else {
die("Could not connect to db.");
}
mysql_select_db('mydb');
$result = mysql_query("SELECT local_name FROM languages;");
while($row = mysql_fetch_array($result)) {
echo $row['local_name'];
echo "<br />";
}
Here is the code I used to query and output the code using CodeIgniter:
Code:
function index() {
echo "<!doctype html>\n";
echo "<html><head><title>test</title>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
echo "</head>";
echo "<body>";
$langs = $this->db->get('languages')->result();
foreach($langs as $lang) {
echo $lang->local_name;
echo "<br />";
}
echo "</body></html>";
}
My CodeIgniter config/config.php setting contains this setting:
Code:
$config['charset'] = 'UTF-8';
My CodeIgniter config/database.php contains these settings:
Code:
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
I spent literally all day yesterday twiddling with various settings for MySQL, Apache, PHP, and CodeIgniter, but the fact that the output works using PHP/mysql and doesn't work with the equivalent code in CodeIgniter suggests to me that the problem exists at the CodeIgniter level. (Although I should add that I am only seeing the problem when I run the code on my Ubuntu testing machine -- when I run similar code on my OSX development machine the CodeIgniter version of the code does run correctly.)
Any ideas for something else to try to get this to work?