Beispiel #1
0
 /**
  * @param integer $fetchType
  * @throws Recipe_Exception_Sql
  * @return array|mixed
  */
 public function fetchAll($fetchType = null)
 {
     if ($fetchType === null) {
         $fetchType = self::DEFAULT_FETCH_TYPE;
     }
     return $this->result->fetch_all($fetchType);
 }
 /**
  * Fetches all the rows as an array of indexed arrays
  *
  * @return array|mixed|null
  */
 public function fetchAllNum()
 {
     if ($this->stored !== null) {
         return $this->stored;
     }
     return $this->result->fetch_all(MYSQLI_NUM);
 }
Beispiel #3
0
 /**
  * 获取所有结果
  *
  * @return array|mixed|null
  */
 public function fetchAll()
 {
     $this->getResult();
     if ($this->result) {
         $this->mysql->num_rows = $this->result->num_rows;
         if (method_exists($this->result, 'fetch_all')) {
             $data = $this->result->fetch_all(MYSQLI_ASSOC);
         } else {
             $data = array();
             while ($row = $this->result->fetch_assoc()) {
                 $data[] = $row;
             }
         }
         return $data;
     } else {
         return null;
     }
 }
 /**
  * @param \mysqli_result $resource
  * @param string         $column
  *
  * @return mixed[]
  */
 protected function fetchResource($resource, $column)
 {
     $fields = $resource->fetch_fields();
     if (count($fields) == 0) {
         return [];
     }
     $result = $resource->fetch_all(MYSQLI_ASSOC);
     if (!is_array($result)) {
         return [];
     }
     $resource->free();
     $this->fixTypes($result, $fields, $column);
     return $result;
 }
Beispiel #5
0
 public function fetch()
 {
     if (!$this->_cursor) {
         return null;
     }
     $res = array();
     if (method_exists('mysqli_result', 'fetch_all')) {
         $res = $this->_cursor->fetch_all(MYSQL_ASSOC);
     } else {
         while ($tmp = $this->_cursor->fetch_array(MYSQL_ASSOC)) {
             $res[] = $tmp;
         }
     }
     return $res;
 }
Beispiel #6
0
 /**
  * 将sql查询结果全部转化成数组
  *
  * @param \mysqli_result $res 要转化的查询
  * @return array 查询的结果
  */
 protected function _fetch_all($res)
 {
     if (method_exists('mysqli_result', 'fetch_all')) {
         $data = $res->fetch_all(MYSQLI_ASSOC);
     } else {
         for ($data = []; $tmp = $res->fetch_array(MYSQLI_ASSOC);) {
             $data[] = $tmp;
         }
     }
     return $data;
 }
Beispiel #7
0
 /**
  * Fetches all result rows and returns the result set as an associative array, a numeric array, or both.
  * @param int $resultType MYSQLI_ASSOC, MYSQLI_NUM or MYSQLI_BOTH
  * @return mixed
  */
 public function fetchAll($resultType = MYSQLI_ASSOC)
 {
     return $this->query->fetch_all($resultType);
 }
Beispiel #8
0
 /**
  * Returns the values of all rows.
  * CAUTION: resets the result pointer.
  * 
  * {@internal Mind the performance: not ifs in while loop}}
  * 
  * @param  int      $resulttype  A DB_Result::FETCH::% constant
  * @param  boolean  $map         Add mapping for roles   
  * @return array
  */
 function getAll($resulttype = DB::FETCH_ORDERED)
 {
     if ($resulttype == DB::FETCH_VALUE) {
         return $this->getColumn();
     }
     $key_field = $this->getFieldIndex('result:key');
     $rows = array();
     $this->native->data_seek(0);
     $opt = $resulttype & ~0xff;
     if (isset($key_field)) {
         switch ($resulttype & 0xff) {
             case DB::FETCH_ORDERED:
                 while ($row = $this->native->fetch_row()) {
                     $rows[$row[$key_field]] = $row;
                 }
                 break;
             case DB::FETCH_ASSOC:
                 while ($row = $this->native->fetch_assoc()) {
                     $rows[$row['result:key']] = $row;
                 }
                 break;
             case DB::FETCH_FULLARRAY:
                 while ($row = $this->native->fetch_array()) {
                     $rows[$row[$key_field]] = $row;
                 }
                 break;
             case DB::FETCH_OBJECT:
                 while ($row = $this->native->fetch_object()) {
                     $rows[$row->{'result:key'}] = $row;
                 }
                 break;
             default:
                 while ($row = $this->fetchRow($resulttype)) {
                     $rows[] = $row;
                 }
                 if (!empty($rows)) {
                     $rows = array_combine($this->getColumn($key_field), $rows);
                 }
                 break;
         }
     } else {
         switch ($resulttype & 0xff) {
             case DB::FETCH_ORDERED:
                 if (function_exists('mysqli_fetch_all')) {
                     $rows = $this->native->fetch_all(MYSQLI_NUM);
                 } else {
                     while ($row = $this->native->fetch_row()) {
                         $rows[] = $row;
                     }
                 }
                 break;
             case DB::FETCH_ASSOC:
                 if (function_exists('mysqli_fetch_all')) {
                     $rows = $this->native->fetch_all(MYSQLI_ASSOC);
                 } else {
                     while ($row = $this->native->fetch_assoc()) {
                         $rows[] = $row;
                     }
                 }
                 break;
             case DB::FETCH_OBJECT:
                 while ($row = $this->native->fetch_object()) {
                     $rows[] = $row;
                 }
                 break;
             case DB::FETCH_FULLARRAY:
                 if (function_exists('mysqli_fetch_all')) {
                     $rows = $this->native->fetch_all(MYSQLI_BOTH);
                 } else {
                     while ($row = $this->native->fetch_array()) {
                         $rows[] = $row;
                     }
                 }
                 break;
             case DB::FETCH_PERTABLE:
                 while ($row = $this->fetchPerTable($opt)) {
                     $rows[] = $row;
                 }
                 break;
             case DB::FETCH_VALUE:
                 while ($row = $this->fetchValue(0, $opt)) {
                     $rows[] = $row;
                 }
                 break;
             case DB::FETCH_RECORD:
                 while ($row = $this->fetchRecord($opt)) {
                     $rows[] = $row;
                 }
                 break;
             case DB::FETCH_ROLES:
                 while ($row = $this->fetchRoles($opt)) {
                     $rows[] = $row;
                 }
                 break;
             default:
                 throw new DB_Exception("Unable to fetch all rows: Unknown result type '{$resulttype}'");
         }
     }
     $this->native->data_seek(0);
     return $rows;
 }
Beispiel #9
0
 public function fetchAll()
 {
     return $this->result->fetch_all();
 }