Welcome Guest, Not a member yet? Register   Sign In
MySQL and extended ASCII


I noticed that string values from my MySQL database are not properly printed with CI. A simple separate PHP script that echoes the same values works fine. However with CI (using an activerecord query) the 'á' will become an '?' and so on.

I am guessing this has something to do with some kind of Character encoding. The MySQL tables are set to 'latin1_swedish_ci'. Is it possible to somehow adjust the char encoding CI uses? Or could something else be the problem?

Running PHP5 with MySQL 5.

Thanks Smile

[eluser]Glen Swinfield[/eluser]
If you use utf-8 encoding in your MySQL tables it will probably work.

In the html header of your pages make sure you set the encoding also:

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

This may help.

Thanks for you help!

Actually, <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> already was in the <head> of each page. However when I remove it, the characters are displayed right!

Would it be better to convert the (existing) database to UTF-8, or can I set it in the header to something else in order to make the characters display right? MyISAM tables in Mysql by default are not UTF-8, so the second option might be best for future use as well?

You should probably switch to 1.5.4. Read the changelog with reference to changing encodings. By default, CI uses UTF-8 internally. As general rule, the encoding you use in MySQL, in CI, and for your HTML should match.

Thanks. It now works, kinda. I set both the page and Mysql tables to UTF-8, which did not work. After converting the database values with utf8_encode() it looks a lot better. However every once in a while there is a strange character. Example:

Quote: Gozando con Shakira…

Por Rocío Saavedra
SALTILLO, COAH. MAYO 31, 2007 (VANGUARDIA).- Todo lo que inicia tiene que finalizar y la más reciente gira de Shakira “Fijación Oral” no fue la excepción, después de un año de 120 conciertos ofrecidos en 36 países desde junio de 2006 Shakira entregó su alma, energía y amor el miércoles por la noche en el Auditorio del Parque Fundidora de Monterrey, Nuevo León.

The weird one here is '…'. Its not supposed to be there, and with normal ISO encoding it is not. Using PHPMyAdmin the (UTF8 encoded) value is displayed as "Gozando con ShakiraÂ…". Which doesnt seem to be right as well.

The other extended characters work fine, as can be seen in the text. Unfortunately the … keeps popping up here-and-there..

Theme © iAndrew 2016 - Forum software by © MyBB