CodeIgniter Forums
Character Enconding + Mysql issues - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Character Enconding + Mysql issues (/showthread.php?tid=13035)



Character Enconding + Mysql issues - El Forum - 11-08-2008

[eluser]Khamusa[/eluser]
Hi all,

i've been programming with PHP for a long, but I have never used any framework. I have now tried CodeIgniter, but i'm facing some issues along the development of very simple mysql tasks.

I need to save some textual information into my mysql table, but with support for latin characters, like "á", "é", and so on... What happens is that when I save these characters into mysql (using $this->db->insert('tablename', $data); in my controller) it saves the info in mysql with question marks (?) replacing these "latin special characters".

So, i try to save, for example, the text "Codeigniter é ótimo" (wich means "Codeigniter is Good") but it saves as "Codeigniter ? ?timo", got it? It's not an issue of different character-encoding on each view, but instead, the insert function SAVES INTO THE MYSQL TABLE already with all the question marks. I made a test, to see when this replacement takes place, and it is surely at the moment of the insert statement, since a simple echo function placed before the insert line displayed the correct information, without the questionmarks, and the phpmyadmin interface displays the ? when I try to view the saved information.

Ah, we have another problem. I am developing this to a client that already has a website wich is completely coded as iso-8859-1, so I can't change anything to utf-8 (although I would really like to). So I have to make it work using iso-8859-1 everywhere (I already changed config.php's default charset to iso-8859-1, and tried using $this->output->set_header("charset:iso-8859-1") before loading each view)


Can anyone help me?
I really hate encoding issues, from the first day I started programming, rs rs rs

cheers
Samuel Brandão


Character Enconding + Mysql issues - El Forum - 11-09-2008

[eluser]Prasanna[/eluser]
Hope this may help you

http://www.nicknettleton.com/zine/php/php-utf-8-cheatsheet


Character Enconding + Mysql issues - El Forum - 11-20-2008

[eluser]mattalexx[/eluser]
I'm having the same problem. Can't write a real estate site in New Mexico without being able to save the word "Cañon". Thanks you for your contribution, Prasanna. That link is really great. But it's not a solution to this problem. If I use phpMyAdmin to save these special characters, it works (including output in a browser). But if I use CI's database class, "Cañon" end up looking like "Ca?on". In other words, my database is configured correctly but I'm doing something wrong in CI.

Anyone have any suggestions?


Character Enconding + Mysql issues - El Forum - 11-20-2008

[eluser]mattalexx[/eluser]
Correction:

Okay, so this is what Codeigniter is inserting and it looks right:

Code:
UPDATE `properties`
SET `mls_lan_coverage` = 'Piñon/Juniper'
WHERE `mls` = '85812'

When I let CI do it though, it doesn't work. But when I copy/paste this SQL into a MySQL command line, it works.

Hmm.


Character Enconding + Mysql issues - El Forum - 06-15-2009

[eluser]deadelvis[/eluser]
Exact same problem here. Have you found a solution? This is driving me a bit insane.


Character Enconding + Mysql issues - El Forum - 06-15-2009

[eluser]mattalexx[/eluser]
[quote author="deadelvis" date="1245105039"]Exact same problem here. Have you found a solution? This is driving me a bit insane.[/quote]

http://www.sitepoint.com/forums/showthread.php?p=4221176


Character Enconding + Mysql issues - El Forum - 06-15-2009

[eluser]deadelvis[/eluser]
hmmm thanks alex.. but since I am using the Active Record.... shouldn't CI be issuing a SET NAMES already? That's what $db['default']['char_set'] under the database config is supposed to be for. Sad


Character Enconding + Mysql issues - El Forum - 06-17-2009

[eluser]mattalexx[/eluser]
[quote author="deadelvis" date="1245109590"]shouldn't CI be issuing a SET NAMES already? That's what $db['default']['char_set'] under the database config is supposed to be for. Sad[/quote]

Yes, I don't know. Is it being called?

You might just try to call it manually to see if it makes a difference. Twice won't hurt.