title: Duplicate entry error for primary key which is autoincrement?
body: <p>I am getting duplicate entry error for primary key which is autoincrement field defined in table.</p>
  
  <pre><code>Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: 
  Integrity constraint violation: 1062 Duplicate entry '0' for key 1' in
  </code></pre>
  
  <p>I am trying to add an entry to the table at the almost same time. That could be the possible reason but i am not sure.</p>
  
  <p>Actually multiple ajax call running behind the scene and they are sometime trying to add entry in table with same primary key at the same time.</p>
  
  <p>I guess this is the issue of autogeneration of same primary key by sql engine.</p>
  
  <p>Mysql table type:MyISAM.</p>
  
  <p>What can be done to fix this?</p>
  
  <p>Table definitions: result_id is a primary key field</p>
  
  <p><img src="https://i.stack.imgur.com/cHGFU.png" alt="Table defintion"></p>
  
  <p>I have writren PDO wrapper for database entry, although i am using this databound object from last year and no issues found. Attaching some portion as requested in comment.</p>
  
  <p>Note: ID(primary key) is not a part of INSERT statement.</p>
  
  <pre><code>$valueList = "";
  $query     = 'INSERT INTO ' . $this-&gt;tableName . ' (';
  
  
  foreach ($this-&gt;relationMap as $key =&gt; $value) {
      eval('$actualVal = &amp;$this-&gt;' . $value . ';');
  
      if (isset($actualVal)) {
          if (array_key_exists($value, $this-&gt;modifiedRelations)) {
              $query .= $key . ', ';
              $valueList .= ":$value, ";
          }
      }
  }
  
  
  $query = substr($query, 0, strlen($query) - 2);
  
  $valueList = substr($valueList, 0, strlen($valueList) - 2);
  $query .= ") VALUES (";
  $query .= $valueList;
  $query .= ")";
  //prepare and execute codes - here
  $this-&gt;ID = $this-&gt;objPDO-&gt;lastInsertId();
  </code></pre>