title: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?'
body: <p>When I execute this code: </p>
  
  <pre><code>$db = new Database();
  $statement = $db-&gt;prepare("SHOW TABLES LIKE :table");            
  if(!$statement)
      throw New Exception($db-&gt;errorInfo()[2]);
  
  foreach($tables as $table){
      $statement-&gt;execute(array(':table' =&gt; $table));
      if($statement-&gt;rowCount() == 0)
          echo 'Table ' . $table . ' doesn\'t exist';
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Exception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1 in something.php on line 4
  </code></pre>
  
  <p>The error isn't thrown when I put single quotes around <code>:table</code> like so: <code>$statement = $db-&gt;prepare("SHOW TABLES LIKE ':table'");</code> - but I thought you weren't supposed to put single quotes around parameters in prepared statements?<br>
  Also, I set this attribute to the database: <code>$db-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES,false);</code>, so that <code>$statement</code> is false when wrong syntax used in the query, so I can throw an exception. The query can be executed when <code>PDO::ATTR_EMULATE_PREPARES</code> is set to true.</p>
  
  <p>My question is: how can I check for errors in my query when using <code>PDO</code> prepared statements? And why do I get the syntax error?</p>