| Subject: | excellent class, it was just what i... |  
| Summary: | Package rating comment |  
| Messages: | 1 |  
| Author: | Camilo Sperberg |  
| Date: | 2009-06-09 21:42:55 |  
|   |  
 
 | 
 | 
Camilo Sperberg rated this package as follows:
| Utility:  | Good | 
| Consistency:  | Good | 
| Examples:  | Good | 
| 
 | 
  Camilo Sperberg - 2009-06-09 21:42:55  
excellent class, it was just what i was looking for. A class that returns all the data within an array, and logs some usage such as number of queries and time taken to do the requests. I could notice only some "bad" things:  
1- if you want to select a complete table ("SELECT * FROM table"), without args, it would throw an exception, So, to resolve that quickly and _very_ dirty, I would make $bind = TRUE only if no args are passed.  
2- microtime() just gives the current second data. It means that if your query takes more than a second, it will give you an inaccurate time. Solved by making $time = time()+microsecond(true); 
3- $types isn't defined at a beginning: it would raise a NOTICE_ERROR if you have the show_startup_errors (or something like that) == TRUE in your php.ini.  
So, the resulting code in:  
private function execute_query($arg_array = NULL) 
 
will be:  
  private function execute_query($arg_array = NULL) { 
    //determine the types of arguments 
    $sql_query=array_shift($arg_array); // the first element is returned to sql_query and then removed 
    $types = ''; 
    foreach ($arg_array as $v) { 
      switch ($v) { 
        case is_string($v): 
          $types.='s'; 
          break; 
        case is_int($v): 
          $types.='i'; 
          break; 
        case is_double($v): 
          $types.='d'; 
           break; 
      } 
    } 
(...) 
    try { 
      if (isset($arg_array[0])) { 
        array_unshift($arg_array, $types); 
        $bind=call_user_func_array(array($this->stmt,'bind_param'),$arg_array); 
      } 
      else $bind = TRUE; 
      if ($bind) { 
        $time_start=time()+microtime(true); 
        $this->stmt->execute(); 
        $this->stmt->store_result(); 
        $time=(time()+microtime(true)) - $time_start; 
 
        $this->log[]=array("query" => $sql_query,"time"  => $time.' seconds'); 
(...) 
 
 
 
Greetings and thanks for such a great class! 
  
   |