SHyx0rmZ

fetch_assoc()

Mar 8th, 2011
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. class mysqli_extended extends mysqli
  2. {
  3.     public function __construct($host, $user, $password, $database)
  4.     {
  5.         parent::__construct($host, $user, $password, $database);
  6.     }
  7.  
  8.     public function prepare($query)
  9.     {
  10.         $stmt = new mysqli_stmt_extended($this, $query);
  11.  
  12.         return $stmt;
  13.     }
  14. }
  15.  
  16. class mysqli_stmt_extended extends mysqli_stmt
  17. {
  18.     protected $vars_bound = false;
  19.     protected $results;
  20.  
  21.     public function __construct($link, $query)
  22.     {
  23.         parent::__construct($link, $query);
  24.     }
  25.  
  26.     public function fetch_assoc()
  27.     {
  28.         if($this->error)print_r($this->error);
  29.         if(!$this->vars_bound)
  30.         {
  31.             $this->store_result();
  32.  
  33.             $meta = $this->result_metadata();
  34.  
  35.             while($column = $meta->fetch_field())
  36.             {
  37.                 $bind_var_array[] = &$this->results[str_replace(' ', '_', $column->name)];
  38.             }
  39.  
  40.             call_user_func_array(array($this, 'bind_result'), $bind_var_array);
  41.  
  42.             $this->vars_bound = true;
  43.         }
  44.  
  45.         if($this->fetch() != null)
  46.         {
  47.             foreach($this->results as $k => $v)
  48.             {
  49.                 $results[$k] = $v;
  50.             }
  51.  
  52.             return $results;
  53.         }
  54.         else
  55.         {
  56.             return null;
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment