title: How to Set Character Set in PDO
body: <p>i've some issue with setting character set in pdo. Below is my connection code :-</p>
  
  <pre><code>private function Connect()
  {
      $this-&gt;settings = parse_ini_file("settings.ini.php");
      //$dsn = 'mysql:dbname='.$this-&gt;settings["dbname"].';host='.$this-&gt;settings["host"].'';
      $dsn = 'mysql:dbname=' . $this-&gt;settings["dbname"] . ';host=' . $this-&gt;settings["host"] .';charset=utf8'. ';connect_timeout=15';
      try 
      {       
          # Read settings from INI file, set UTF8
          $this-&gt;pdo = new PDO($dsn, $this-&gt;settings["user"], $this-&gt;settings["password"], array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET NAMES utf8"));
  
          # We can now log any exceptions on Fatal error. 
          $this-&gt;pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
          # Disable emulation of prepared statements, use REAL prepared statements instead.
          $this-&gt;pdo-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  
          # Connection succeeded, set the boolean to true.
          $this-&gt;bConnected = true;
      }
      catch (PDOException $e) 
      {
          # Write into log
          echo $this-&gt;ExceptionLog($e-&gt;getMessage());
          die();
      }
  }
  </code></pre>
  
  <p>I am inserting french character as <code>céréales</code> but it is storing as      <code>cÃ©rÃ©ales</code> in DB. Anyone know how to set character set to utf8 in pdo?</p>