示例#1
0
 /**
  * Fetch all the rows allowing access to each row with a callback or 
  * closure
  *
  * @param	int		$type
  * @param	mixed	string | array | closure
  * @return	array
  */
 public function fetchAllData(ErrorStackInterface $errorStack, $type = MYSQLI_ASSOC, $filter = null)
 {
     if (!$this->isHandle()) {
         $errorStack->addError("Result handle is not available", 500);
         return false;
     }
     if (!$this->isValidType($type)) {
         $this->free();
         $err = "fetchAllData failed: invalid result type -({$type})";
         $errorStack->setError($msg, 500);
         return false;
     }
     /*
      * No need to go foward knowing the callback is faulty
      */
     if (!is_callable($filter) && !empty($filter)) {
         $msg = 'fetchAllData failed: invalid callback';
         $errorStack->seError($msg, 500);
         return false;
     }
     $idx = 0;
     $handle = $this->getHandle();
     $data = array();
     $error = array();
     while ($row = $handle->fetch_array($type)) {
         if (!is_callable($filter)) {
             $data[] = $row;
             $idx++;
             continue;
         }
         try {
             $data[] = call_user_func($filter, $row);
         } catch (Exception $e) {
             $errText = $e->getMessage() . " -({$idx})";
             $errorStack->addError($errText, $e->getCode());
             $data[] = false;
         }
         $idx++;
     }
     $this->free();
     return $data;
 }