title: PHP PDO mySQL query create table if not exist
body: <p>Using PHP PDO query to execute a mySQL query. The query is made up of a multitude of information inputted from foreach(); so I have echo'd out the sql query. The problem lies here but I cannot see it.</p>
  
  <p>This is the output of <code>$sql</code></p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE IF NOT EXISTS `page` (
    `page_ID` INT AUTO_INCREMENT NOT NULL,
    `url` varchar(200) NOT NULL,
    `title` varchar(200),
    `subtitle` TEXT,
    `content` TEXT,
    `parent` varchar(10),
    `privacy` varchar(1),
    `status` varchar(1),
    `creation` varchar(30)
  ) CHARACTER SET utf8 COLLATE utf8_general_ci;
  </code></pre>
  
  <p>FYI the query is executed like this:</p>
  
  <pre><code>function createdbtable($table,$fields){
      global $fsdbh;
      $sql = "CREATE TABLE IF NOT EXISTS `$table` (";
      foreach($fields as $field =&gt; $type){ $sql.= "`$field` $type,"; }
      $sql = rtrim($sql,',');
      $sql .= ") CHARACTER SET utf8 COLLATE utf8_general_ci"; return $sql;
      if($fsdbh-&gt;exec($sql) !== false) { return 1; }
  }
  </code></pre>
  
  <p>This is the error:</p>
  
  <blockquote>
    <p>#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key</p>
  </blockquote>