title: UTF-8 MySQL and Charset
body: <p>Can someone explain me when I set everything to UTF-8 I keep getting those damn ���</p>
  
  <p>MySQL<br />
  Server version: 5.1.44<br />
  MySQL charset:  UTF-8 Unicode (utf8)</p>
  
  <p>I create a new database</p>
  
  <p>name: utf8test<br />
  collation: utf8_general_ci<br />
  MySQL connection collation: utf8_general_ci<br /></p>
  
  <p>My SQL looks like this:</p>
  
  <pre><code>SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
  
  CREATE TABLE IF NOT EXISTS `test_table` (
      `test_id` int(11) NOT NULL,
      `test_text` text NOT NULL,
      PRIMARY KEY (`test_id`)
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  
  INSERT INTO `test_table` (`test_id`, `test_text`) VALUES
  (1, 'hééélo'),
  (2, 'wööörld');
  </code></pre>
  
  <p>My PHP / HTML:</p>
  
  <pre><code>&lt;?php
  $db_conn = mysql_connect("localhost", "root", "") or die("Can't connect to db");
  mysql_select_db("utf8test", $db_conn)  or die("Can't select db");
  
  // $result = mysql_query("set names 'utf8'"); // this works... why??
  $query = "SELECT * FROM test_table";        
  $result = mysql_query($query);
  
  $output = "";
  while($row = mysql_fetch_assoc($result)) {
      $output .= "id: " . $row['test_id'] . " - text: " . $row['test_text'] . "&lt;br /&gt;";
  }
  ?&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html lang="it" xmlns="http://www.w3.org/1999/xhtml" xml:lang="it"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;UTF-8 test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php echo $output; ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>