title: Inserting UTF-8 encoded string into UTF-8 encoded mysql table fails with "Incorrect string value"
body: <p>Inserting UTF-8 encoded string into UTF-8 encoded table gives incorrect string value.</p>
  
  <blockquote>
    <p>PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x9D\x84\x8E i...' for column 'body_value' at row 1: INSERT INTO</p>
  </blockquote>
  
  <p>I have a <code></code> character, in a string that <a href="http://php.net/manual/en/function.mb-detect-encoding.php" rel="noreferrer">mb_detect_encoding</a> claims is UTF-8 encoded.
  I try to insert this string into a MySQL table, which is defined as (among other things) <code>DEFAULT CHARSET=utf8</code></p>
  
  <p><strong>Edit:</strong> Drupal always does <code>SET NAMES utf8</code> with optional <code>COLLATE</code> (atleast when talking to MySQL).</p>
  
  <p><strong>Edit 2:</strong> Some more details that appear to be relevant. I grab some text from a PostgreSQL database. I stick it onto an object, use mb_detect_encoding to verify that it's UTF-8, and persist the object to the database, using <a href="http://api.drupal.org/api/drupal/modules!node!node.module/function/node_save/7" rel="noreferrer">node_save</a>. So while there is an HTTP request that triggers the import, the data does not come from the browser.</p>
  
  <p><strong>Edit 3:</strong> Data is denormalized over two tables:</p>
  
  <blockquote>
    <p>SELECT character_set_name FROM information_schema.<code>COLUMNS</code> C WHERE table_schema = "[database]" AND table_name IN ("field_data_body", "field_revision_body") AND column_name = "body_value";</p>
  </blockquote>
  
  <pre><code>&gt;+--------------------+
  | character_set_name |
  +--------------------+
  | utf8               |
  | utf8               |
  +--------------------+
  </code></pre>
  
  <p><strong>Edit 4:</strong> Is it possible that the character is "to new"? I'm more than a little fuzzy on <a href="https://stackoverflow.com/questions/643694/utf-8-vs-unicode">the relationship between unicode and UTF-8</a>, but this <a href="http://en.wikipedia.org/wiki/List_of_Unicode_characters#Musical_symbols" rel="noreferrer">wikipedia article</a>, implies that the character was standardized very recently.</p>
  
  <p>I don't understand how that can fail with "Incorrect string value".</p>