title: Forcing encoding & decoding with Doctrine 2
body: <p>I'm working with a legacy <a href="http://en.wikipedia.org/wiki/Big_ball_of_mud" rel="nofollow">big ball of mud</a> that uses a <code>latin1</code> database but works with <code>utf8</code> strings. Each time the application reads or writes to database, it decodes or encodes <em>by hand</em> and stores <code>utf8</code> encoded strings in the <code>latin1</code> database.</p>
  
  <p>When writing, it does something like:</p>
  
  <pre class="lang-php prettyprint-override"><code>$value = utf8_encode("Iñtërnâtiônàlizætiøn")
  mysql_query("INSERT INTO table (key) VALUES ($value)")
  </code></pre>
  
  <p>So the stored value is <code>IÃ±tÃ«rnÃ¢tiÃ´nÃ lizÃ¦tiÃ¸n</code></p>
  
  <p>And when reading:</p>
  
  <pre class="lang-php prettyprint-override"><code>$result = mysql_query("SELECT key FROM table")
  $value = utf8_decode($result) // Wich results on "Iñtërnâtiônàlizætiøn" again
  </code></pre>
  
  <p>How can I manage the same database using Doctrine 2 and respecting that strange behaviour?</p>
  
  <p>The following code will work as expected when used in my <code>Entity</code>, but I'm looking for a cleaner and DRY solution.</p>
  
  <pre><code>public function setKey($value)
  {
      $this-&gt;key = utf8_encode($value);
  }
  
  public function getKey()
  {
      return utf8_decode($this-&gt;key);
  }
  </code></pre>