Welcome to the Treehouse Community
Looking to learn something new?
Jonathan Söder5,771 Points
Not have to specify Charset in connection? PHP and MYSQL
I've got a minor problem that's really annoying me.
I've set database, table and my php file to UTF-8.
If I echo swedish characters they show up in the browser. Fine.
However if I retrieve swedish characters from the database they show up as "?".
AKA something's wrong with the decoding.
When I specify charset with mysqli_set_charset() in my connection snippet characters decode properly.
It's been a while since I coded but I'm pretty sure I never had to specify a charset in my connection before.
If the same charset is set everywhere, you shouldn't have to specify the charset in the connection, right? Does anyone have any hunch of what's going on here?
everything works fine with mysqli_set_charset.
Without function, the info fetched from db displays special chars as "?".
DB, Table & phpfile set to UTF-8.
simple php echo's displays special chars fine.
Why is function needed when everything's set to same charset?
Andrew Winkler37,737 Points
I've never run into such an error before, but I did understand what you were asking. I found the answer on a stack overflow thread.
After connecting and before making any queries.
Your database charset is just for storage, not for transmission between app and database.