title: PHP - PDO Query executing twice when execute() is only called once
body: <p>I have looked everywhere for an answer to this and tried everything I have found here on StackOverflow and other sites.</p>
  
  <p>Basically what's happening is that whenever I execute an SQL query, PDO is executing it twice even when <code>execute()</code> is only called once...</p>
  
  <p>Here is my code...</p>
  
  <pre><code>&lt;?php
  namespace quizazle;
  
  class sql{
    private $username = 'x';
    private $passwd = '';
    private $port = 3306;
    private $host = 'x';
    private $name = 'x';
    private $charSet = 'utf8mb4';
  
    private $db = null;
  
    public function __construct(){
      $this-&gt;db = new \PDO("mysql:host=$this-&gt;host;dbname=$this-    &gt;name;charset=$this-&gt;charSet", $this-&gt;username, $this-&gt;passwd);
      $this-&gt;db-&gt;setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
      $this-&gt;db-&gt;setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
      $this-&gt;db-&gt;setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
    }
  
    private function bind($q, $p){
      try{
        $s = $this-&gt;db-&gt;prepare($q);
        if(!empty($p)){
          foreach ($p as $pm){
            $s-&gt;bindParam($pm['key'], $pm['value']);
          }
        }
      }
      catch(PDOException $e){
        echo($e-&gt;getMessage());
      }
      return $s;
    }
  
    public function query($query, $params){
      try{
        $statement = $this-&gt;bind($query, $params);
        $statement-&gt;execute();
        $res = $statement-&gt;fetchAll(\PDO::FETCH_BOTH);
  
        return $res;
      }
      catch(PDOException $e){
        echo($e-&gt;getMessage());
      }
    } 
  
    public function update($query, $params){
      try{
        $statement = $this-&gt;bind($query, $params);
        $statement-&gt;execute();
        $res = $statement-&gt;rowCount();
  
        return $res;
      }
      catch(PDOException $e){
        echo($e-&gt;getMessage());
      }
    }
  }
  ?&gt;
  </code></pre>
  
  <p>and here is the code where I am using the <code>sql</code> class...</p>
  
  <pre><code>$sql = new quizazle\sql();
  
  $params = array(
    array(
      'key' =&gt; 'd',
      'value' =&gt; 'a'
    )
  );
  
  $result = $sql-&gt;update("INSERT INTO `test` (`data`) VALUES(:d)", $params);
  
  var_dump($result);
  </code></pre>
  
  <p>I have tried...</p>
  
  <ul>
  <li>removing <code>var_dump($result);</code></li>
  <li>not binding parameters, although that is a bad way to go for me, it still doesn't work.</li>
  <li>changing <code>$this-&gt;db-&gt;setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);</code> to <code>$this-&gt;db-&gt;setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);</code></li>
  <li>changing <code>$this-&gt;db-&gt;setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);</code> to <code>$this-&gt;db-&gt;setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);</code></li>
  </ul>
  
  <p>yet none of this has worked. Any help will be greatly appreciated and thank you all in advance :)</p>
  
  <p>PS: I discovered this problem while running INSERT statements, if that helps at all.</p>