title: PDO MySQL dsn charset not working
body: <p>I'm trying the following code over Lubuntu 12.04, Apache, PHP 5.5.3-1ubuntu2, pdo_mysql 5.5.32 and MySQL 5.5.32-0ubuntu7-log.</p>
  
  <pre><code>$dbh = new \PDO("mysql:host=$hostname;dbname=test_db;charset=utf-8", $username, $password);
  
  $dbh-&gt;exec('SET NAMES utf8');
  
  $sql = "SELECT name FROM test_table";
  foreach ($dbh-&gt;query($sql) as $row) {
      error_log(bin2hex($row['name']));
  }
  </code></pre>
  
  <p>And I get <code>44656d6f737472616369c3b36e</code>. If I comment the <code>SET NAMES utf8</code> query, I get <code>44656d6f737472616369f36e</code> (the difference being <code>c3b3</code> instead of <code>f3</code>).</p>
  
  <p>From the MySQL client, When issuing <code>SELECT HEX(name) FROM test_table limit 1;</code> I get <code>44656D6F737472616369C3B36E</code>.</p>
  
  <p>So it seems the extra query is needed, but according to <a href="http://php.net/manual/en/ref.pdo-mysql.connection.php" rel="nofollow noreferrer">this</a> it shouldn't.</p>
  
  <p>Am I doing something wrong? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I tried both with <code>charset=utf-8</code> and <code>charset=utf8</code> and I'm getting the same result.</p>
  
  <p>Output of <code>SHOW CREATE TABLE test_table</code>:</p>
  
  <pre><code>CREATE TABLE `test_table` (
      `name` varchar(255) DEFAULT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  </code></pre>
  
  <p>Relevant output of <a href="https://stackoverflow.com/questions/7617412/discover-collation-of-a-mysql-column"><code>SHOW FULL COLUMNS FROM test_table</code></a>:</p>
  
  <pre><code>+-------+--------------+-----------------+
  | Field | Type         | Collation       |
  +-------+--------------+-----------------+
  | name  | varchar(255) | utf8_general_ci |
  +-------+--------------+-----------------+
  </code></pre>