CodeIgniter Forums
MySQL and extended ASCII - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: MySQL and extended ASCII (/thread-2033.html)



MySQL and extended ASCII - El Forum - 07-12-2007

[eluser]Xandrios[/eluser]
Hi,

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


MySQL and extended ASCII - El Forum - 07-12-2007

[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:

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

This may help.


MySQL and extended ASCII - El Forum - 07-12-2007

[eluser]Xandrios[/eluser]
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?


MySQL and extended ASCII - El Forum - 07-12-2007

[eluser]esra[/eluser]
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.


MySQL and extended ASCII - El Forum - 07-20-2007

[eluser]Xandrios[/eluser]
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..