MySQL issue with character set
Today i stumbled upon an issue with inserting text into a database, and the character set wasn’t taking it. No mather what i changed in the database, it was inserted wrong time after time.
Characters like â and é are shown wrong. In the variable it is correct, but in database it isn’t.
This is what i had:
<?php $string = "é á â ê ô ç ö"; $db->query(" UPDATE mytable SET mytxt = '".$string."' WHERE id=1"); // using ezSQL ?>
But when i looked into the database it wasn’t correct. Wrong encoding. The tabel was set UTF-8 so that couldn’t be wrong.
This was my solution:
<?php $string = "é á â ê ô ç ö"; $db->query(" SET CHARACTER SET utf8 "); $db->query(" UPDATE mytable SET mytxt = '".$string."' WHERE id=1"); // using ezSQL ?>
Now it was correct inserted, so i could use it properly.