title: PDOStatement::fetchAll() :SQLSTATE[HY000]:
body: <p>This error return to me when I executed the code </p>
  
  <blockquote>
    <p>Warning: PDOStatement::fetchAll() [pdostatement.fetchall]: SQLSTATE[HY000]: General error: Extraneous additional parameters in C:\AppServ\www\cms_project\lib\database_model.class.php on line 28</p>
    
    <p>Warning: array_shift() [function.array-shift]: The argument should be an array in C:\AppServ\www\cms_project\lib\database_model.class.php on line 34</p>
    
    <p>Warning: Invalid argument supplied for foreach() in C:\AppServ\www\cms_project\lib\cat.class.php on line 43</p>
  </blockquote>
  
  <p>this is database_model class:</p>
  
  <pre><code>&lt;?php
  
  class database_model
  {
  public function attribute()
  {
  $string = array();
  foreach($this-&gt;db_feild as $feild){
  
  if(is_int($this-&gt;$feild) || is_double($this-&gt;$feild)){
  $string[] = $feild . " = ".$this-&gt;$feild."";
  
  }else{
  $string[] = $feild ." = '".$this-&gt;$feild ."'";
  }
  }
  return implode(', ',$string); // convert array to string
  }
  
  
  
  public static function read($sql, $type = PDO::FETCH_ASSOC,$class = null)
  {
  
  global $db_connect;
  $resualt= $db_connect-&gt;query($sql); // query from db
  if($resualt){
  if(null !== $class &amp;&amp; $type == PDO::FETCH_ASSOC){
  $data = $resualt-&gt;fetchAll($type,$class);
  
  }else{
  $data = $resualt-&gt;fetchAll($type);
  }
  if(count($data)== 1){
  $data = array_shift($data); // array_shift  علشان نطلع من الارارى
  }
  return $data;
  }else{
  return false;
  }
  
  }
  
  
  private function add()
  {
  global $db_connect; // to use the conection to database
  
  $sql = "INSERT INTO ".$this-&gt;table_name . " SET " .$this-&gt;attribute();
  
  $affectedrows = $db_connect-&gt;exec($sql); // to include to database
  if($affectedrows != false){
  $this-&gt;id = $db_connect-&gt;lastInsertId();
  }else{
  return false;
  }
  return true;
  }
  
  
  private function update()
  {
  global $db_connect;
  $sql = "UPDATE ".$this-&gt;table_name . " SET " .$this-&gt;attribute()
  ."WHERE id = ".$this-&gt;id;
  $affectedrows = $db_connect-&gt;exec($sql);
  return $affectedrows != false ? true : false;
  
  }
  
  
  
  public function delete()
  {
  global $db_connect;
  $sql = "DELETE FROM ".$this-&gt;table_name."WHERE id = ".$this-&gt;id;
  $affectedrows = $db_connect-&gt;exec($sql);
  return $affectedrows != false ? true : false;
  
  } 
  
  
  
  public function save()
  {
  return ($this-&gt;id === null)? $this-&gt;add():$this-&gt;update();
  }
  }
  ?&gt;
  </code></pre>
  
  <p>this is cat class :
      
  
  <pre><code>class cat extends database_model
  {
  public $id; 
  public $user_id;
  public $created;
  public $title;
  public $slug;
  public $content;
  
  public $table_name = 'cat';
  
  public $db_feild = array(
  'user_id',
  'created',
  'title',
  'slug',
  'content',
  
  );
  
  public static function control()
  {
  // __CLASS__ ==&gt; RETURN THE THIS CLASS 
  $all_categries = self::read("SELECT * FROM cat ",PDO::FETCH_ASSOC,__CLASS__);
  
  $table = '&lt;table class="cpanel_cat"&gt;';
  $table .= '&lt;tr&gt;
  &lt;th&gt;# &lt;/th&gt;
  &lt;th&gt;category name &lt;/th&gt;
  &lt;th colspan="2"&gt; control &lt;/th&gt;
  '  ;
  if($all_categries !== false){
  if(is_object($all_categries)){
  $table .= '&lt;tr&gt;
  &lt;td&gt;1 &lt;/td&gt;
  &lt;td&gt;'. $all_categries-&gt;title .'&lt;/td&gt;
  &lt;td&gt;&lt;a href="" &gt;EDIT&lt;/a&gt; | &lt;a href="" &gt; Delete&lt;/a&gt; &lt;/td&gt;
  ';    
  }else{
  $i = 1;
  foreach($all_categries as $cat)
  $table .= '&lt;tr&gt;
  &lt;td&gt;'.$i++ .' &lt;/td&gt;
  &lt;td&gt;'.$cat-&gt;title .'&lt;/td&gt;
  &lt;td&gt;&lt;a href="" &gt;EDIT&lt;/a&gt; | &lt;a href="" &gt; Delete&lt;/a&gt; &lt;/td&gt;
  ';    
  }
  }else{
  $table .= '&lt;tr&gt;&lt;td colspan="4"&gt;sorry categroy not found !!&lt;/td&gt;&lt;/tr&gt;';
  }
  $table .='&lt;/table&gt;';
  return $table; 
  }
  
  }
  </code></pre>