CodeIgniter Forums

Full Version: Help with MySQL character sets and collations
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Daniel Peraza[/eluser]
Hi!, I'm using the Active Record Class to store user-edited data into a MySQL 5 DB, which uses utf8_general_ci as collation. The problem is that A.R.C. is not sanitizing the data properly and when I try to use spanish characters such as áéíóúñ, the data is stored in the DB as áéí&At;.

My database.php config file has these settings:

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

El Forum

[eluser]Jiacomo[/eluser]
I have the same problem!

[quote author="Daniel Peraza" date="1226717970"]Hi!, I'm using the Active Record Class to store user-edited data into a MySQL 5 DB, which uses utf8_general_ci as collation. The problem is that A.R.C. is not sanitizing the data properly and when I try to use spanish characters such as áéíóúñ, the data is stored in the DB as áéí&At;.

My database.php config file has these settings:

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

El Forum

[eluser]bitist[/eluser]
Check if your database tables collation is utf8_general_ci.
You can check this with PHPMyAdmin Collation row.

El Forum

[eluser]Jiacomo[/eluser]
Hi, thanks for the reply.
My tables collation is "utf8_unicode_ci", so I set:

$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_unicode_ci";

...

El Forum

[eluser]bitist[/eluser]
I don't know the difference between the 2 collation, but I used utf8_general_ci, so you should try to convert one of you table to utf8_general_ci and maybe that'll work for you.

El Forum

[eluser]Daniel Peraza[/eluser]
Well, in my case I had it done previously. But my problem was that I was starting to learn CI and I wasn't sure that Active Record Queries would escape values properly before executing its statements. So I had left some code somewhere to automatically escape string values by calling
Code:
htmlentities()
, and of course, the result was the substitution of all accented vowels by its corresponding html entities. I had forgotten this piece of code but when I realized of it, I remove it and all worked wonderful.

El Forum

[eluser]Skuja[/eluser]
In what encoding your controller/view files ar encoded in ?