public function result($a_type = null)
 {
     if (!$this->m_result or !$this->m_result instanceof mysqli_result) {
         return $this->m_result;
     }
     $r = array();
     do {
         $row = false;
         switch ($a_type) {
             default:
             case ZDatabase::RESULT_TYPE_NUM:
                 $row = $this->m_result->fetch_array(MYSQLI_NUM);
                 break;
             case ZDatabase::RESULT_TYPE_ASSOC:
                 $row = $this->m_result->fetch_array(MYSQLI_ASSOC);
                 break;
             case ZDatabase::RESULT_TYPE_BOTH:
                 $row = $this->m_result->fetch_array(MYSQLI_BOTH);
                 break;
             case ZDatabase::RESULT_TYPE_OBJECT:
                 $row = $this->m_result->fetch_object();
                 break;
             case ZDatabase::RESULT_TYPE_RAW:
                 return $this->m_result;
         }
         if (!$row) {
             break;
         }
         $r[] = $row;
     } while (1);
     return $r;
 }
Пример #2
0
 /**
  * Извлечение данных
  *
  * @return array|null
  */
 protected function fetch()
 {
     if (!$this->isValidResult()) {
         return null;
     }
     return $this->query_result->fetch_array($this->fetch_type);
 }
Пример #3
0
 public function result($a_type = null, $a_arg = null)
 {
     if (!$this->m_result) {
         return $this->m_result;
     }
     if ($this->m_result->num_rows() === false) {
         return false;
     }
     $r = array();
     do {
         $row = false;
         switch ($a_type) {
             default:
             case Zoombi_Database::RESULT_TYPE_NUM:
                 $row = $this->m_result->fetch_array(MYSQLI_NUM);
                 break;
             case Zoombi_Database::RESULT_TYPE_ASSOC:
                 $row = $this->m_result->fetch_array(MYSQLI_ASSOC);
                 break;
             case Zoombi_Database::RESULT_TYPE_BOTH:
                 $row = $this->m_result->fetch_array(MYSQLI_BOTH);
                 break;
             case Zoombi_Database::RESULT_TYPE_OBJECT:
                 $row = func_num_args() > 1 ? $this->m_result->fetch_object(func_get_arg(1)) : $this->m_result->fetch_object();
                 break;
             case Zoombi_Database::RESULT_TYPE_RAW:
                 return $this->m_result;
         }
         if (!$row) {
             break;
         }
         $r[] = $row;
     } while (1);
     return $r;
 }
Пример #4
0
 /**
  * Get result data.
  * @param int The row number from the result that's being retrieved. Row numbers start at 0.
  * @param int The offset of the field being retrieved.
  * @return array|false The contents of one cell from a MySQL result set on success, or false on failure.
  */
 public function query_result($row, $field = 0)
 {
     if (0 == $this->result->num_rows) {
         return false;
     }
     $this->result->data_seek($row);
     $datarow = $this->result->fetch_array();
     return $datarow[$field];
 }
Пример #5
0
 /**
  * @see \Iterator::current()
  *
  * @return mixed
  * @throws \OutOfRangeException
  */
 public function current()
 {
     // Seems overkill to define our own OutOfRangeException. Use default in this case
     if ($this->_pointer > $this->_numberOfRows - 1) {
         throw new \OutOfRangeException('Attempting to access a row that is outside of the number of rows in this result.');
     }
     $pointer = $this->_pointer;
     if (!array_key_exists($this->_pointer, $this->_mysqlResult)) {
         $this->_mysqlResult[$this->_pointer] = $this->_result->fetch_array(\MYSQLI_ASSOC);
         $this->_pointer++;
         $this->_moveToNextRow = true;
         $this->_processedRows++;
         // Free up results when there is no more row to process
         if ($this->_processedRows === $this->_numberOfRows) {
             $this->_result->free();
         }
     }
     return $this->_mysqlResult[$pointer];
 }
Пример #6
0
 /**
  * Obtenemos un elemento del resultado.
  * @param int $type Tipo de retorno de los valores.
  * @param int|array $cast Cast a aplicar a los elementos.
  * @return mixed
  * @author Ignacio Daniel Rostagno <*****@*****.**>
  */
 public function get_record($type = Database_Query::FETCH_ASSOC, $cast = NULL)
 {
     // $this->next();
     switch ($type) {
         case Database_Query::FETCH_NUM:
             // Obtenemos el arreglo.
             $resultado = $this->query->fetch_array(MYSQLI_NUM);
             // Evitamos cast de consultas erroneas o vacias.
             if (!is_array($resultado)) {
                 return $resultado;
             }
             // Expandimos listado de cast.
             $cast = $this->expand_cast_list($cast, count($resultado));
             // Realizamos el cast.
             $c = count($resultado);
             for ($i = 0; $i < $c; $i++) {
                 $resultado[$i] = $this->cast_field($resultado[$i], $cast[$i]);
             }
             return $resultado;
         case Database_Query::FETCH_OBJ:
             // Obtenemos el objeto.
             $object = $this->query->fetch_object();
             // Evitamos cast de consultas erroneas o vacias.
             if (!is_object($object)) {
                 return $object;
             }
             // Expandimos la lista de cast.
             $cast = $this->expand_cast_list($cast, array_keys(get_object_vars($object)));
             // Realizamos el cast.
             foreach ($cast as $k => $v) {
                 $object->{$k} = $this->cast_field($object->{$k}, $v);
             }
             return $object;
         case Database_Query::FETCH_ASSOC:
         default:
             // Obtenemos el arreglo.
             $resultado = $this->query->fetch_array(MYSQLI_ASSOC);
             // Evitamos cast de consultas erroneas o vacias.
             if (!is_array($resultado)) {
                 return $resultado;
             }
             // Expandimos la lista de cast.
             $cast = $this->expand_cast_list($cast, array_keys($resultado));
             // Realizamos el cast.
             foreach ($cast as $k => $v) {
                 $resultado[$k] = $this->cast_field($resultado[$k], $v);
             }
             return $resultado;
     }
 }
 /**
  * @param \mysqli_result $result
  * @param $returnMode
  * @return \Generator
  */
 public function rowGenerator(\mysqli_result $result, $returnMode)
 {
     switch ($returnMode) {
         case self::RETURN_TYPE_ASSOC:
             (yield $result->fetch_assoc());
             break;
         case self::RETURN_TYPE_NUM:
             (yield $result->fetch_array(MYSQLI_NUM));
             break;
         case self::RETURN_TYPE_BOTH:
             (yield $result->fetch_array(MYSQLI_BOTH));
             break;
         case self::RETURN_TYPE_MYSQLI_ROW:
             (yield $result->fetch_row());
             break;
         case self::RETURN_TYPE_OBJ:
             (yield $result->fetch_object());
             break;
         default:
             (yield $result->fetch_assoc());
             break;
     }
 }
Пример #8
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;
 }
Пример #9
0
 /**
  * Implementation of the next() method.
  *
  * @return array|null The next row in the resultset or null if there are no
  * more results.
  */
 public function next()
 {
     if (is_null($this->_result)) {
         $this->rewind();
     }
     if ($this->_result) {
         $row = $this->_result->fetch_array(MYSQLI_BOTH);
         if (!$row) {
             $this->_eof = true;
         } else {
             $this->_eof = false;
             if (is_null($this->_index)) {
                 $this->_index = 0;
             } else {
                 ++$this->_index;
             }
             $this->_current = $row;
         }
     }
     return $this->_current;
 }
Пример #10
0
 function arow(&$data)
 {
     $data = $this->result->fetch_array(MYSQLI_ASSOC);
     return !empty($data);
 }
Пример #11
0
 public function fetch_array(mysqli_result $r)
 {
     //return mysql_fetch_array($r);
     return $r->fetch_array();
 }
Пример #12
0
 /**
  * @param mysqli_result $result
  * @param int $mode
  * @return mixed
  */
 public function fetch_array($result, $mode = self::RESULT_NUM)
 {
     return $result->fetch_array($mode);
 }
Пример #13
0
Файл: Result.php Проект: jasny/Q
 /**
  * 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;
 }
Пример #14
0
 /**
  * Returns array with numerical and string keys of the current row or null if no more rows are in the result
  * @param integer $type type of returned array
  * @return array|null
  */
 public function fetchArray($type = self::BOTH)
 {
     return $this->dbResult->fetch_array($type);
 }
Пример #15
0
 /**
  * @param integer $column
  * @throws Recipe_Exception_Sql
  * @return mixed
  */
 public function fetchColumn($column = 0)
 {
     $data = $this->result->fetch_array(MYSQLI_NUM);
     return $data[$column];
 }
Пример #16
0
 /**
  * returns all results as associative array
  * @param \mysqli_result $result result of last executed query
  * @return mixed[]
  */
 public function fetch_array($result)
 {
     return $result->fetch_array();
 }
Пример #17
0
 /**
  * Returns an array of strings that corresponds to the fetched row or NULL if there are no more rows in resultset.
  * @param int $resultType MYSQLI_ASSOC, MYSQLI_NUM or MYSQLI_BOTH
  * @return mixed
  */
 public function fetchRow($resultType = MYSQLI_ASSOC)
 {
     return $this->query->fetch_array($resultType);
 }
Пример #18
0
 /**
  * Retrieves record from a recordset
  *
  * Gets the next record in a recordset and returns in array
  *
  * @param    mysqli_result $recordSet The record set to operate on
  * @param    bool          $both      get both assoc and numeric indices
  * @return   array       Returns data array of current row from recordset
  */
 public function dbFetchArray($recordSet, $both = false)
 {
     $result_type = $both ? MYSQLI_BOTH : MYSQLI_ASSOC;
     $result = $recordSet->fetch_array($result_type);
     return $result === null ? false : $result;
 }
Пример #19
0
	/**
	 * Convierte una instancia de mysqli_result en una tabla html
	 * @param  mysqli_result $mysqli_result instancia de mysqli_result
	 * @param  function $afterTrCallback funcion a llamar justo despues
	 * de cada apertura de tr de la tabla. Se le pasan dos parametros,
	 * número de fila (0 para la fila de encabezados) y un array con
	 * los datos de la fila (datos de la primera fila para el tr del
	 * encabezado)
	 * @return string Marcado html de la tabla
	 */
	public static function result_to_html_table ($mysqli_result,$afterTrCallback=NULL) {
		$result='';
		$result.='<table border="1" style="width:100%;">';
		$i=0;
		while ($columnInfo = $mysqli_result->fetch_array(MYSQLI_ASSOC)) {
			if ($i==0) {
				$result.='	<tr>';
				if (!is_null($afterTrCallback)) {$result.=$afterTrCallback($i,$columnInfo);}
				foreach ($columnInfo as $key => $value) {
					$result.='		<th>'.$key.'</th>';
				}
				$result.='	</tr>';
			}
			$i++;
			$result.='	<tr>';
			if (!is_null($afterTrCallback)) {$result.=$afterTrCallback($i,$columnInfo);}
			foreach ($columnInfo as $key => $value) {
				$result.='		<td>'.$value.'</td>';
			}
			$result.='	</tr>';
		}
		$result.='</table>';
		return $result;
	}
Пример #20
0
 /**
  * 从sql查询的结果中获取一条数据
  *
  * @param \mysqli_result $res sql查询结果
  * @return array 获取的数据,或者false
  */
 protected function _fetch($res)
 {
     return $res->fetch_array(MYSQLI_ASSOC);
 }
Пример #21
0
 public function fetchArray($param = MYSQLI_ASSOC)
 {
     return $this->result->fetch_array($param);
 }
Пример #22
0
 /**
  * @param mysqli_result $res
  * @return array|bool
  */
 protected function mysqlFetchArray($res)
 {
     Assert::true($res instanceof mysqli_result, __METHOD__);
     $array = $res->fetch_array();
     if ($array === null) {
         return false;
     }
     return $array;
 }
Пример #23
0
 /**
  * Get result data
  *
  * @param mysqli_result $query
  *   The result resource that is being evaluated. This result comes from a call to mysql_query().
  * @param int $row
  *   The row number from the result that's being retrieved. Row numbers start at 0.
  * @param mixed[int|string] $field
  *   The name or offset of the field being retrieved.
  *   It can be the field's offset, the field's name, or the field's table dot field name (tablename.fieldname). If the column name has been aliased ('select foo as bar from...'), use the alias instead of the column name. If undefined, the first field is retrieved.
  * @return mixed
  *   The contents of one cell from a MySQL result set on success, or FALSE on failure.
  */
 function result($query, $row = 0, $field = 0)
 {
     $ret = FALSE;
     if ($query instanceof mysqli_result && $query->num_rows) {
         $query->data_seek($row);
         $ret = $query->fetch_array(is_numeric($field) ? MYSQLI_NUM : MYSQLI_ASSOC);
         if ($ret) {
             $ret = $ret[$field];
         }
     }
     return $ret;
 }
Пример #24
0
 /**
  * used to read next record from the recordset - user is responsible to check
  * if next arrived to end of recordset
  *
  * @param int $type of result to return. defaults to MYSQLI_ASSOC. Can be: MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH
  * @return array
  */
 public function getRow($type = MYSQLI_ASSOC)
 {
     $this->currentRecord = $this->ResultSet->fetch_array($type);
     return $this->currentRecord;
 }
Пример #25
0
 /**
  * 从结果集中取得一行作为关联数组/数字索引数组
  */
 function fetch_array(mysqli_result $query, $type = MYSQLI_ASSOC)
 {
     return $query->fetch_array($type);
 }
Пример #26
0
 function Read()
 {
     $this->row = $this->result->fetch_array(MYSQLI_BOTH);
     return $this->row !== null;
 }