title: PHP MySQL utf-8 Euro symbol shown as questionmark on a diamond
body: <p>So after a whole day of googling and debugging I end up here.</p>
  
  <h1>MySQL</h1>
  
  <p>set to the following encoding:</p>
  
  <pre><code>db:  utf8_general_ci
  table: utf8_general_ci
  column: utf8_general_ci, TEXT
  </code></pre>
  
  <p>I put in some euro symbols and some other weird characters</p>
  
  <blockquote>
    <p>acentuação €€€€€</p>
  </blockquote>
  
  <h1>PHP (codeigniter)</h1>
  
  <p>config</p>
  
  <pre><code>$config['charset'] = 'UTF-8';
  </code></pre>
  
  <p>dsn</p>
  
  <pre><code>char_set=utf8,dbcollat=utf8_general_ci
  </code></pre>
  
  <p>I made some queries to compare</p>
  
  <h3>model</h3>
  
  <pre><code>$query = $this-&gt;db-&gt;query("SET NAMES latin1");
  $query = $this-&gt;db-&gt;query("SELECT shortdesc,HEX(shortdesc) FROM `contracttypes` WHERE id = 4");
  $ret['latin1'] =  $query-&gt;row();
  $query = $this-&gt;db-&gt;query("SET NAMES utf8");
  $query = $this-&gt;db-&gt;query("SELECT shortdesc,HEX(shortdesc) FROM `contracttypes` WHERE id = 4");
  $ret['utf8'] =  $query-&gt;row();
  return $ret;;
  </code></pre>
  
  <h3>controller</h3>
  
  <pre><code>public function utfhell()  {
  var_dump($this-&gt;campagne_model-&gt;utfhell());
  }
  </code></pre>
  
  <p>This outputs</p>
  
  <pre><code>array (size=2)
  'latin1' =&gt; 
  object(stdClass)[34]
  public 'shortdesc' =&gt; string 'acentua��o �����' (length=16)
  public 'HEX(shortdesc)' =&gt; string '6163656E747561C3A7C3A36F20E282ACE282ACE282ACE282ACE282AC' (length=56)
  'utf8' =&gt; 
  object(stdClass)[33]
  public 'shortdesc' =&gt; string 'acentuação €€€€€' (length=28)
  public 'HEX(shortdesc)' =&gt; string '6163656E747561C3A7C3A36F20E282ACE282ACE282ACE282ACE282AC' (length=56)
  </code></pre>
  
  <p>So far so good, on to a </p>
  
  <h1>view</h1>
  
  <pre><code>&lt;?php header('Content-Type: text/html; charset="utf-8"', true); ?&gt;
  &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;UTFhell&lt;/title&gt;
  &lt;link rel="stylesheet" href="../assets/css/style.css"/&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8"&gt;
  ...
  &lt;?php
  echo 'Original : ', $campagne_info-&gt;contractName-&gt;shortdesc."&lt;br /&gt;";
  echo 'UTF8 Encode : ', utf8_encode($campagne_info-&gt;contractName-&gt;shortdesc)."&lt;br /&gt;";
  echo 'UTF8 Decode : ', utf8_decode($campagne_info-&gt;contractName-&gt;shortdesc)."&lt;br /&gt;";
  echo 'TRANSLIT : ', iconv("ISO-8859-1", "UTF-8//TRANSLIT", $campagne_info-&gt;contractName-&gt;shortdesc)."&lt;br /&gt;";
  echo 'IGNORE TRANSLIT : ', iconv("ISO-8859-1", "UTF-8//IGNORE//TRANSLIT", $campagne_info-&gt;contractName-&gt;shortdesc)."&lt;br /&gt;";
  echo 'IGNORE   : ', iconv("ISO-8859-1", "UTF-8//IGNORE", $campagne_info-&gt;contractName-&gt;shortdesc)."&lt;br /&gt;";
  echo 'Plain: ', iconv("ISO-8859-1", "UTF-8", $campagne_info-&gt;contractName-&gt;shortdesc)."&lt;br /&gt;";
  echo '€€€€€€€€€€&lt;br&gt;'; 
  ?&gt;
  </code></pre>
  
  <p>None of these now show me a normal euro symbol except the final echo statement, they all give me questionmark diamonds for the eurosymbols </p>