title: Arabic characters doesn't add in pdo
body: <p>I have a pdo class works great with English but when I try to insert Arabic text it doesn't work well</p>
  
  <p>This the class:</p>
  
  <pre><code>class DB extends config
  {
          # @object, The PDO object
          protected $pdo;
  
          # @object, PDO statement object
          private $sQuery;
  
          # @bool ,  Connected to the database
          private $bConnected = false;
  
          # @object, Object for logging exceptions    
          private $log;
  
          # @array, The parameters of the SQL query
          private $parameters;
  
          protected $table;
          protected $values;
         /**
          *   Default Constructor 
          *
          *   1. Instantiate Log class.
          *   2. Connect to database.
          *   3. Creates the parameter array.
          */
                  public function __construct($table)
                  { 
                          parent::__construct();
                          $this-&gt;log = new Log(); 
                          $this-&gt;Connect();
                          $this-&gt;parameters = array();
                          $this-&gt;table = $table;
                  }
  
         /**
          *   This method makes connection to the database.
          *   
          *   1. Reads the database settings from a ini file. 
          *   2. Puts  the ini content into the settings array.
          *   3. Tries to connect to the database.
          *   4. If connection failed, exception is displayed and a log file gets created.
          */
                  private function Connect()
                  {
                          $dsn = 'mysql:dbname='.$this-&gt;settings["dbname"].';host='.$this-&gt;settings["host"];
                          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();
                          }
                  }
          /*
           *   You can use this little method if you want to close the PDO connection
           *
           */
                  public function CloseConnection()
                  {
                          # Set the PDO object to null to close the connection
                          # http://www.php.net/manual/en/pdo.connections.php
                          $this-&gt;pdo = null;
                  }
  
         /**
          *   Every method which needs to execute a SQL query uses this method.
          *   
          *   1. If not connected, connect to the database.
          *   2. Prepare Query.
          *   3. Parameterize Query.
          *   4. Execute Query.   
          *   5. On exception : Write Exception into the log + SQL query.
          *   6. Reset the Parameters.
          */  
                  private function Init($query,$parameters = "")
                  {
                  # Connect to database
                  if(!$this-&gt;bConnected) { $this-&gt;Connect(); }
                  try {
                                  # Prepare query
                                  $this-&gt;sQuery = $this-&gt;pdo-&gt;prepare($query);
  
                                  # Add parameters to the parameter array 
                                  $this-&gt;bindMore($parameters);
  
                                  # Bind parameters
                                  if(!empty($this-&gt;parameters)) {
                                          foreach($this-&gt;parameters as $param)
                                          {
                                                  $parameters = explode("\x7F",$param);
                                                  $this-&gt;sQuery-&gt;bindParam($parameters[0],$parameters[1]);
                                          }       
                                  }
  
                                  # Execute SQL 
                                  $this-&gt;succes   = $this-&gt;sQuery-&gt;execute();     
                          }
                          catch(PDOException $e)
                          {
                                          # Write into log and display Exception
                                          echo $this-&gt;ExceptionLog($e-&gt;getMessage(), $query );
                                          die();
                          }
  
                          # Reset the parameters
                          $this-&gt;parameters = array();
                  }
  
         /**
          *   @void 
          *
          *   Add the parameter to the parameter array
          *   @param string $para  
          *   @param string $value 
          */  
                  public function bind($para, $value)
                  {   
                          $this-&gt;parameters[sizeof($this-&gt;parameters)] = ":" . $para . "\x7F" . utf8_encode($value);
                  }
         /**
          *   @void
          *   
          *   Add more parameters to the parameter array
          *   @param array $parray
          */  
                  public function bindMore($parray)
                  {
                          if(empty($this-&gt;parameters) &amp;&amp; is_array($parray)) {
                                  $columns = array_keys($parray);
                                  foreach($columns as $i =&gt; &amp;$column) {
                                          $this-&gt;bind($column, $parray[$column]);
                                  }
                          }
                  }
         /**
          *       If the SQL query  contains a SELECT or SHOW statement it returns an array containing all of the result set row
          *   If the SQL statement is a DELETE, INSERT, or UPDATE statement it returns the number of affected rows
          *
          *       @param  string $query
          *   @param  array  $params
          *   @param  int    $fetchmode
          *   @return mixed
          */          
                  public function query($query,$params = null, $fetchmode = PDO::FETCH_ASSOC)
                  {
                          $query = trim($query);
  
                          $this-&gt;Init($query,$params);
  
                          $rawStatement = explode(" ", $query);
  
                          # Which SQL statement is used 
                          $statement = strtolower($rawStatement[0]);
  
                          if ($statement === 'select' || $statement === 'show') {
                                  return $this-&gt;sQuery-&gt;fetchAll($fetchmode);
                          }
                          elseif ( $statement === 'insert' ||  $statement === 'update' || $statement === 'delete' ) {
                                  return $this-&gt;sQuery-&gt;rowCount();   
                          }   
                          else {
                                  return NULL;
                          }
                  }
  
        /**
         *  Returns the last inserted id.
         *  @return string
         */   
                  public function lastInsertId() {
                          return $this-&gt;pdo-&gt;lastInsertId();
                  }   
  
         /**
          *   Returns an array which represents a column from the result set 
          *
          *   @param  string $query
          *   @param  array  $params
          *   @return array
          */  
                  public function column($query,$params = null)
                  {
                          $this-&gt;Init($query,$params);
                          $Columns = $this-&gt;sQuery-&gt;fetchAll(PDO::FETCH_NUM);     
  
                          $column = null;
  
                          foreach($Columns as $cells) {
                                  $column[] = $cells[0];
                          }
  
                          return $column;
  
                  }   
         /**
          *   Returns an array which represents a row from the result set 
          *
          *   @param  string $query
          *   @param  array  $params
          *       @param  int    $fetchmode
          *   @return array
          */  
                  public function row($query,$params = null,$fetchmode = PDO::FETCH_ASSOC)
                  {               
                          $this-&gt;Init($query,$params);
                          return $this-&gt;sQuery-&gt;fetch($fetchmode);            
                  }
         /**
          *   Returns the value of one single field/column
          *
          *   @param  string $query
          *   @param  array  $params
          *   @return string
          */  
                  public function single($query,$params = null)
                  {
                          $this-&gt;Init($query,$params);
                          return $this-&gt;sQuery-&gt;fetchColumn();
                  }
         /**  
          * Writes the log and returns the exception
          *
          * @param  string $message
          * @param  string $sql
          * @return string
          */
          private function ExceptionLog($message , $sql = "")
          {
                  $exception  = 'Unhandled Exception. &lt;br /&gt;';
                  $exception .= $message;
                  $exception .= "&lt;br /&gt; You can find the error back in the log.";
  
                  if(!empty($sql)) {
                          # Add the Raw SQL to the Log
                          $message .= "\r\nRaw SQL : "  . $sql;
                  }
                          # Write into log
                          $this-&gt;log-&gt;write($message);
  
                  return $exception;
          }
          public function binding($values = array()){
              foreach($values as $key =&gt; $value){
                  $this-&gt;bind($key,$value);
                  $this-&gt;values[$key] = $value;
              }
          }
          public function add($where = NULL){
              $sql = "INSERT INTO {$this-&gt;table} (";
              $i=0;
              foreach($this-&gt;values as $key =&gt; $value){
                  if($i+1 == count($this-&gt;values))
                  {
                      $sql.= $key;
                  }  
                  else 
                  {
                      $sql.= $key.',';
                  }
  
                  $i++;
              }
              $sql .= ') values (';
              $i=0;
              foreach($this-&gt;values as $key =&gt; $value){
                  if($i+1 == count($this-&gt;values))
                  {
                      $sql.= ":{$key}";
                  }  
                  else 
                  {
                      $sql.= ":{$key},";
                  }
  
                  $i++;
              }
              $sql .= ')';
              if(!empty($where)){
                  $sql+=$where;
              }
              $query = $this-&gt;query($sql);
              return $query;
          }
          public function delete($id){
              $sql = "DELETE FROM {$this-&gt;table} WHERE id = :id";
              $this-&gt;bind("id",$id);
              $query = $this-&gt;query($sql);
              return $query;
          }
          public function update($where){
              $sql= "UPDATE {$this-&gt;table} SET";
              $i=0;
              foreach($this-&gt;values as $key =&gt; $value){
                  if($i == count($this-&gt;values))
                  {
                      $sql.= "{$key} = ':{$key}'";
                  }  
                  else 
                  {
                      $sql.= "{$key} = ':{$key}',";
                  }
                  $i++;
              }
              $sql .= $where;
              $query = $this-&gt;query($sql);
              return $query;
          }
  }
  </code></pre>
  
  <p>when i use it as this </p>
  
  <pre><code>include_once './includes/int.php';
  $db = new Db("test");
  $db-&gt;binding(array(
      "test" =&gt; "ابلابا"
  ));
  $add = $db-&gt;add();
  print_r( $db-&gt;row("select * from test where id = 5"));
  </code></pre>
  
  <p>it gives me this</p>
  
  <pre><code>Array ( [id] =&gt; 5 [test] =&gt; Ø§Ø¨ÙØ§Ø¨Ø§ ) 
  </code></pre>
  
  <p>I make the collection of the columns in phpMyadmin</p>
  
  <pre><code>utf8mb4_unicode_ci
  </code></pre>
  
  <p><strong>edit:</strong></p>
  
  <p>My table collection is</p>
  
  <pre><code>utf8_unicode_ci
  </code></pre>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>I had checked all this <a href="https://stackoverflow.com/questions/279170/utf-8-all-the-way-through">question</a> but all of this i have already made it </p>
  
  <p><strong>edit 3:</strong></p>
  
  <pre><code>&lt;?php header('Content-Type: text/html; charset=utf-8');?&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;title&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
  &lt;?php
  include_once './includes/int.php';
  $db = new Db("test");
  $db-&gt;binding(array(
      "test" =&gt; "ابلابا"
  ));
  $add = $db-&gt;add();
  print_r( $db-&gt;row("select * from test where id = 12"));
  ?&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and still doesn't work</p>