title: Json encode - invalid utf-8 sequence
body: <p>Everything I've been doing that anyhow relates to the databases throw me the json_encode(): invalid utf-8 sequence warning.</p>
  
  <p>Earlier it was because of the doctrine usage, I couldn't deal with it so I began doing something else in my project...but now I need to use the PDO connection in one place, and the problem has returned.</p>
  
  <p>The warning appears even with some random database configs (but where host = 'localhost').</p>
  
  <hr>
  
  <p>The code:</p>
  
  <pre><code>$dsn = 'mysql:dbname='.$form['dbname']-&gt;getData().';host='.$form['host']-&gt;getData();
  $pdo = new \PDO($dsn, $form['username']-&gt;getData(), $form['password']-&gt;getData());
  </code></pre>
  
  <hr>
  
  <p>Input example:</p>
  
  <pre><code>dbname = 'fdsfdsf'
  username = 'fdsfdsf'
  password = 'fsdfds'
  host = 'localhost'
  </code></pre>
  
  <hr>
  
  <p>The exact error:</p>
  
  <pre><code>ContextErrorException: Warning: json_encode(): Invalid UTF-8 sequence in argument in C:\xampp\htdocs\cc\app\cache\dev\classes.php line 4520
  </code></pre>
  
  <hr>
  
  <p>What have I tried already?</p>
  
  <ol>
  <li>mysql_set_charset()</li>
  <li>Escaping input strings</li>
  <li><code>@</code> syntax</li>
  <li>Setting utf8 encoding for the controller file</li>
  <li><p>Setting utf8-general encoding for mysql tables/database</p>
  
  <pre><code>$dsn = 'mysql:dbname='.htmlentities($form['dbname']-&gt;getData(), ENT_QUOTES, 'utf-8', FALSE).';host='.htmlentities($form['host']-&gt;getData(), ENT_QUOTES, 'utf-8', FALSE);
  $pdo = @new \PDO($dsn, htmlentities($form['username']-&gt;getData(), ENT_QUOTES, 'utf-8', FALSE), htmlentities($form['password']-&gt;getData(), ENT_QUOTES, 'utf-8', FALSE));
  mysql_set_charset('utf-8');
  </code></pre></li>
  </ol>
  
  <p><strong>What's wrong?</strong></p>