title: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'id'
body: <p>Having a problem with "<strong>SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'id'</strong>" here,</p>
  
  <pre><code>&lt;? if (!defined("sKEY")) { exit("Houston, We've Got a Problem"); }
  class PDOAct
  {
      public $db;
      function __construct()
      {
          try {
              $this-&gt;db = new PDO(DBdriver.':host='.DBhost.';dbname='.DBbase, DBuser, DBpass);
              $this-&gt;db-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
          } catch(PDOException $e) {
              $this-&gt;err($e-&gt;getMessage());
          }
      }
      //
      //
      function select($base, $row, $val, $type)
      {
          try {
              if (isset($row[0]) &amp;&amp; isset($val[0]) &amp;&amp; isset($type[0]))
              {
                  if (isset($base['select']) &amp;&amp; $base['select'] != "*")
                  {
                      for ($i=0; $i&lt;count($row); $i++)
                      {
                          if ($i &lt; 1)
                          {
                              $q = "SELECT `".$base['select']."` FROM `".$base['table']."` WHERE `".$row[$i]."` = ':".$row[$i]."'";
                          } else {
                              $q = $q." AND `".$row[$i]."` = ':".$row[$i]."'";
                          }
                      }
                  } elseif (!isset($base[select]) || $base[select] == "*") {
                      for ($i=0; $i&lt;count($row); $i++)
                      {
                          if ($i &lt; 1)
                          {
                              $q = "SELECT * FROM `".$base['table']."` WHERE `".$row[$i]."` = ':".$row[$i]."'";
                          } else {
                              $q = $q." AND `".$row[$i]."` = ':".$row[$i]."'";
                          }
                      }
                  }
              } elseif (!isset($row[0]) &amp;&amp; !isset($val[0]) &amp;&amp; !isset($type[0])) {
                  if ($base['select'] != "" &amp;&amp; $base['select'] != "*")
                  {
                      $q = "SELECT `".$base['select']."` FROM `".$base['table']."`";
                  } elseif ($base['select'] == "" || $base['select'] == "*") {
                      $q = "SELECT * FROM `".$base['table']."`";
                  }
              } else {
                  exit("Query error!");
              }
              $do = $this-&gt;db-&gt;prepare($q);
          } catch(PDOException $e) {
              $this-&gt;err($e-&gt;getMessage());
          }
          $arr = array('do' =&gt; $do, 'row' =&gt; $row, 'val' =&gt; $val, 'type' =&gt; $type);
          return $arr;
      }
      //
      //
      function insert($base, $row, $val, $type)
      {
          try {
              if (isset($row[0]) &amp;&amp; isset($val[0]) &amp;&amp; isset($type[0]))
              {
                  for ($i=0; $i&lt;=count($row); $i++)
                  {
                      if ($i &lt; 1)
                      {
                          $q = "INSERT INTO `".$base['table']."` (`".$row[$i]."`";
                      } elseif ($i == count($row)) {
                          $q = $q.") VALUES (";
                          for ($j=0; $j&lt;=count($row); $j++)
                          {
                              if ($j &lt; 1)
                              {
                                  $q = $q."':".$row[$j]."'";
                              } elseif ($j == count($row)) {
                                  $q = $q.")";
                              } else {
                                  $q = $q.", ':".$row[$j]."'";
                              }
                          }
                      } else {
                          $q = $q.", `".$row[$i]."`";
                      }
                  }
              } else {
                  exit("Query error!");
              }
              $do = $this-&gt;db-&gt;prepare($q);
          } catch(PDOException $e) {
              $this-&gt;err($e-&gt;getMessage());
          }
          $arr = array('do' =&gt; $do, 'row' =&gt; $row, 'val' =&gt; $val, 'type' =&gt; $type);
          return $arr;
      }
      //
      //
      function execute($arr)
      {
          $do = $arr['do'];
          $row = $arr['row'];
          $val = $arr['val'];
          $type = $arr['type'];
          try {
              for ($i=0; $i&lt;count($row); $i++)
              {
                  $bindrow = ':'.$row[$i];
                  $bindtype = "PDO::PARAM_".strtoupper($type[$i]);
                  $do-&gt;bindValue($bindrow, $val[$i], $bindtype);
              }
              $do-&gt;execute();
          } catch(PDOException $e) {
              $this-&gt;err($e-&gt;getMessage());
          }
      }
      //
      //
      function err($e)
      {
          file_put_contents('log'.DIR_SEP.'PDOerrors.txt', $e."\n", FILE_APPEND);
          exit("Houston, We've Got a Problem");
      }
  }
  ?&gt;
  </code></pre>
  
  <p>when i try to do insert query like this:</p>
  
  <pre><code>$db = new PDOAct;
      $base   = array("table" =&gt; "users");
      $row    = array("id",  "login", "pass",  "level", "date",       "name",  "sex", "birth");
      $val    = array( 4,    "Paul",   135246,   2,     "2013-06-22", "Paulio",  1,    "1996-06-25");
      $type   = array("int", "str",   "int",   "int",   "str",        "str",   "int", "str");
      $res = $db-&gt;execute($db-&gt;insert($base, $row, $val, $type));
      print_r($res);
  </code></pre>
  
  <p>In the table I have two entries with id 0 &amp; 1, so it cannot duplicate id..<br>
  So what's the problem?<br>
  Thank you!</p>