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.
3 Comments »
RSS feed for comments on this post. TrackBack URL
Hi Renee,
could I instert more characters in that string?
Like the strange ř from Dvořák.
I am a php dummie, so…
best, Frank.
Hey,
yeah you can insert everything you want. The string can be as long as you want.
Good luck!
Hi Reneee!!!
Thanks for your nice advice!!! I had that problem and now thanks to you I resolved!!! THANKS THANKS THANKS!!!!