Ad

Character Set And Collation Messed Up?

- 1 answer

I'm writing an html5 web page to store input from users in a MySQL database. The web page has tags <html lang="en">, <meta charset="utf-8"> and <form ... accept-charset="utf-8">.

I'm using PHP 5.4 and MariaDB 5.5.44. The database's character's set to UTF8. The table's character's set to UTF8. Collation is set to utf8_general_ci.

Why am I getting weird characters in my database? E.g. when I upload "á" it becomes "á"?

I'm pretty much a noob at coding and the docs go above my skill level.

Ad

Answer

Try this: Directly after the DB connection initialisation, insert

$mydb->set_charset("utf8");

(where $mydb is the variable for your db connection) In my case this helped in a similar situation.

Ad
source: stackoverflow.com
Ad