How do I make MySQL return UTF-8? How do I make MySQL return UTF-8? xml xml

How do I make MySQL return UTF-8?


You have to define the connection to your database as UTF-8:

// Set up your connection$connection = mysql_connect('localhost', 'user', 'pw');mysql_select_db('yourdb', $connection);mysql_query("SET NAMES 'utf8'", $connection);// Now you get UTF-8 encoded stuff$query = sprintf('SELECT name FROM place where id = 1');$result = mysql_query($query, $connection);$result = mysql_fetch_assoc($result);


From version PHP 5.5.0 you should use

mysqli_set_charset($connection,"utf8");