Welcome Guest, Not a member yet? Register   Sign In
Character encoding, CodeIgniter and MySQL
#1

[eluser]Gaz[/eluser]
Hi all,

Just wondering if anybody can help me out with a character encoding problem with MySQL and CI.

Basically I'm importing data from an Excel spreadsheet into MySQL. The spreadsheet gets converted to an array, and some of the fields have foreign-language accented characters, such as é and å.

These characters display fine when I output them to the browser from the array, but when they get inserted into the database they appear as '?'.

The variables returned from the query "show variables like 'character%'" come back as

Code:
character_set_client        utf8
character_set_connection    utf8
character_set_database        utf8
character_set_filesystem    binary
character_set_results        utf8
character_set_server        utf8
character_set_system        utf8
character_sets_dir        /usr/share/mysql/charsets/

I'm using

Code:
header("Content-Type: text/html; charset=utf-8");

on every view, and the database.php config file includes the lines

Code:
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

The results from

Code:
$this->db->last_query();

also show the characters as '?', although they are fine before the query.

Cheers,
Gaz.
#2

[eluser]TheFuzzy0ne[/eluser]
Have you also tried adding:
Code:
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

to the head of your document, and validating your source code at http://validator.w3.org?
#3

[eluser]Gaz[/eluser]
I've got that in the header of all my pages, yeah.

I don't think validating the source of the page is going to help really. This issue is that when the data is sent to the database, certain characters are converted to question marks.

Both CI, PHP and MySQL are all set up to use UTF-8, but it seems I'm obviously missing something somewhere.

Cheers,
Gaz.
#4

[eluser]TheFuzzy0ne[/eluser]
Oh I see. I thought that problem was outputting it from the database, not storing it.

Do you have some kind of Web interface for your database? If so, you might want to try adding some data that way, and seeing how it displays. Also, check the collation of your tables. If the table is UTF8, then the data should be stored with that encoding. If the problem is with a server which you don't maintain, then it would probably be better to speak to your service provider.
#5

[eluser]Iván Argulo[/eluser]
I don't use UTF-8 in Spanish language (nor in CodeIgniter nor in MySQL) because I couldn't to make it work.

For CodeIgniter I use iso-8859-1 (both in meta and config), and for MySQL I use latin1_spanish_ci, or latin1_general_ci, because we have too special chars such á and ñ. I found that with other charsets the data gets encoded in the database.

Maybe you'll have to choose your charset other than UTF.

Hope it helps
#6

[eluser]j2more[/eluser]
Hey, I know this maybe way too late but check out http://ellislab.com/forums/viewthread/124298/ rgds ben




Theme © iAndrew 2016 - Forum software by © MyBB