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; }
/** * Извлечение данных * * @return array|null */ protected function fetch() { if (!$this->isValidResult()) { return null; } return $this->query_result->fetch_array($this->fetch_type); }
/** * @param mysqli_result $mysqli_result * @param bool $single * @return array|bool|null */ public function fetch($mysqli_result, $single) { $this->_('fields', array()); foreach ($mysqli_result->fetch_fields() as $field) { $this->_('fields')[$field->name] = $this->rules[$this->types[$field->type]]; } switch (true) { case !$mysqli_result: return null; case $single && $mysqli_result->num_rows == 0: $result = false; break; case $single: $result = $this->cast($mysqli_result->fetch_assoc()); break; case $mysqli_result->num_rows == 0: $result = array(); break; default: $result = array(); while ($row = $mysqli_result->fetch_assoc()) { $result[] = $this->cast($row); } } $mysqli_result->free(); return $result; }
/** * @param Entity $entity * @return EntityManagerMysqli */ protected function fetch(\mysqli_result $result, Entity $entity = null) { while ($data = $result->fetch_assoc()) { $this->add($entity->getClone()->serialize($data)); } return $this; }
/** * (non-PHPdoc) * @see Phine/Framework/Database/Interfaces/IDatabaseReader#Close() */ function Close() { if (!$this->IsClosed()) { $this->result->close(); $this->closed = true; } }
/** * Очищение результатов */ protected function freeResult() { if ($this->query_result !== null) { $this->query_result->free_result(); $this->query_result = null; } $this->result = null; }
public function nextRecord() { if (is_object($this->handle) && ($data = $this->handle->fetch_assoc())) { return $data; } else { return false; } }
/** * * 关闭 stmt result mysqli的函数,传入这三个东西就行 * @param mysqli,stmt,result */ static function close(mysqli $mysqli = null, mysqli_stmt $stmt = null, mysqli_result $result = null) { if ($result != null) { $result->free(); } if ($stmt != null) { $stmt->close(); } if ($mysqli != null) { $mysqli->close(); } }
/** * @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; }
function loadDefaultData($totalCount, mysqli_result $result) { if ($totalCount == 0) { echo "暂无资讯"; return; } else { if ($totalCount > 0) { $cnt = 0; while ($row = $result->fetch_assoc()) { if ($cnt < DEFAULT_SHOW) { $list_id = $row["info_id"]; echo "<div class=\"list\">"; echo "<a href=\"" . $row["origin_link"] . "\" class=\"nav_list\" data-id={$list_id} onclick=\"count({$list_id})\">"; echo "<p class=\"caption\">"; echo $row["caption"]; echo "</p>"; echo "<p class=\"subhead\">"; echo $row["subhead"]; echo "</p>"; echo "<div class=\"footer\">"; echo "<span class=\"text_des\">"; echo $row["origin"]; echo "</span>"; echo " "; echo " "; echo "<span class=\"num_des\">"; echo substr($row["publish_date"], 5, 5); echo "</span>"; echo " "; echo " "; echo "<div class=\"like\">"; echo "<img src=\"../images/grayheart.png\" class=\"icon\">"; echo "<span class=\"info_like\">"; echo showFavNum($row["fav"]); echo "</span>"; echo "</div>"; echo "</div>"; echo "<img src=\"" . $row["pic_link"] . "\" class=\"show_pic\">"; echo "</a>"; echo "</div>"; echo "<hr/>"; $cnt++; } else { break; return; } } } } }
function loadDefaultData($totalCount, mysqli_result $result) { if ($totalCount == 0) { return; } else { if ($totalCount > 0) { $cnt = 0; while ($row = $result->fetch_assoc()) { if ($cnt < DEFAULT_SHOW) { $list_id = $row["info_id"]; echo "<div class=\"list\">"; echo "<a href=\"" . $row["origin_link"] . "\" class=\"e_wine_list\" data-id={$list_id} onclick=\"count({$list_id})\">"; echo "<p class=\"wine_caption\">"; echo $row["caption"]; echo "</p>"; echo "<p class='wine_subhead'>"; echo $row['subhead']; echo "</p>"; echo "<div class=\"wine_footer\">"; echo "<span class=\"wine_orgin\">"; echo $row["origin"]; echo "</span>"; echo " "; echo " "; echo "<span class=\"wine_price\">"; echo $row["publish_date"]; echo "</span>"; echo " "; echo " "; echo "<div class=\"wine_fav\">"; echo "<img src=\"../images/grayheart.png\" class=\"icon\">"; echo "<span class=\"wine_fav_num\">"; echo showFavNum($row["fav"]); echo "</span>"; echo "</div>"; echo "</div>"; echo "<img src=\"" . $row["pic_link"] . "\" class=\"wine_show_pic\">"; echo "</a>"; echo "</div>"; echo "<hr/>"; $cnt++; } else { break; return; } } } } }
public function queryRows($sql) { $aaData = array(); if (!$sql) { return false; } if (!$this->real_query($sql)) { throw new exception($this->error, $this->errno); } $result = new mysqli_result($this); while ($row = $result->fetch_object()) { $aaData[] = $row; } return $aaData; }
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; }
/** * @en Get element from query result as an object * @ru Получить первую запись из ответа базы данных в виде объекта * * $database = new database(); # do not forget to declare defines before calling this class: * # > RUDE_DATABASE_USER * # > RUDE_DATABASE_PASS * # > RUDE_DATABASE_HOST * # > RUDE_DATABASE_NAME * * $database->query('SELECT * FROM users WHERE 1 = 1'); * * $result = $database->get_object(); # stdClass Object * # ( * # [id] => 2 * # [username] => manager * # [hash] => 0991b08461e5ce0ee0a038c104b5a6d3 * # [salt] => nLpUwvzSpD5yoqXtqjvhtqwhJUsMFh8P * # [role_id] => 2 * # ) * * @return mixed */ public function get_object() { if ($object = $this->result->fetch_object()) { return $object; } return null; }
/** * Returns the current row of a result set under HHVM * The problem was fetch_object creates new instance of a given class, * and attaches resulted key/value pairs after the class was constructed. * * @return mixed */ private function currentHHVM() { if ($this->_as_object === TRUE or is_string($this->_as_object)) { if ($this->_reflect_class === NULL) { // Create reflection class of given classname or stdClass $this->_reflect_class = new ReflectionClass(is_string($this->_as_object) ? $this->_as_object : 'stdClass'); } // Support ORM with loaded, when the class has __set and __construct if its ORM if ($this->_reflect_class->hasMethod('__set') === TRUE && $this->_reflect_class->hasMethod('__construct') === TRUE) { // Get row as associated array $row = $this->_result->fetch_assoc(); // Get new instance without constructing it $object = $this->_reflect_class->newInstanceWithoutConstructor(); foreach ($row as $column => $value) { // Trigger the class setter $object->__set($column, $value); } // Construct the class with no parameters $object->__construct(NULL); return $object; } elseif (is_string($this->_as_object)) { // Return an object of given class name return $this->_result->fetch_object($this->_as_object, (array) $this->_object_params); } else { // Return an stdClass return $this->_result->fetch_object(); } } // Get row as associated array return $this->_result->fetch_assoc(); }
/** * Binds this statement to the variables */ protected function bind() { $variables = array(); // Bind each field while ($field = $this->metadata->fetch_field()) { $this->columns[] = $field->name; // Note that while boundValues isn't initialised at this point, // later calls to $this->statement->fetch() Will populate // $this->boundValues later with the next result. $variables[] =& $this->boundValues[$field->name]; } call_user_func_array(array($this->statement, 'bind_result'), $variables); $this->bound = true; $this->metadata->free(); // Buffer all results $this->statement->store_result(); }
function display_results(mysqli_result $res) { // Table header: echo '<table class="tbl"> <tr> <th>Host</th> <th>User</th> </tr> '; // Fetch and print all the records: while ($row = $res->fetch_object()) { echo '<tr> <td>' . $row->host . '</td> <td>' . $row->user . '</td> </tr>'; } echo '</table>'; }
/** * Rewind * */ public function rewind() { $this->currentComplete = false; $this->position = 0; if ($this->resource instanceof \mysqli_stmt) { //$this->resource->reset(); } else { $this->resource->data_seek(0); // works for both mysqli_result & mysqli_stmt } }
/** * Rewind */ public function rewind() { if ($this->position !== 0) { if ($this->isBuffered === false) { throw new Exception\RuntimeException('Unbuffered results cannot be rewound for multiple iterations'); } } $this->resource->data_seek(0); // works for both mysqli_result & mysqli_stmt $this->currentComplete = false; $this->position = 0; }
/** * Load the column metadata from the last query. * @return array */ public function load_col_info() { if ($this->col_info) { return $this->col_info; } $num_fields = $this->result->field_count; for ($i = 0; $i < $num_fields; $i++) { $this->col_info[$i] = $this->result->fetch_field_direct($i); } return $this->col_info; }
function loadMore($page, mysqli_result $result) { $pos = 0; $cnt = 0; $arry = array(); while ($row = $result->fetch_assoc()) { if ($pos != $page * DEFAULT_SHOW) { $pos++; continue; } else { if ($cnt < DEFAULT_SHOW) { array_push($arry, $row); $cnt++; } else { break; return; } } } return json_encode($arry, JSON_UNESCAPED_UNICODE); }
/** * 释放资源 */ public function free() { if ($this->result) { $this->result->free(); $mysql = $this->mysql->connect(); while ($mysql->more_results() && $mysql->next_result()) { $result = $mysql->store_result(); if ($result) { $result->free(); } } } }
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; }
/** * Get all array data * * @return array */ public function getFetchArrays() { $data = array(); if ($this->resource instanceof \mysqli_result) { $result = $this->resource; } else { if ($this->resource instanceof \mysqli_stmt) { $result = $this->resource->get_result(); } else { if ($this->resource instanceof \mysqli) { $result = $this->resource->store_result(); } } } while ($row = $result->fetch_array(\MYSQLI_ASSOC)) { $data[] = $row; } return $data; }
/** * 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; }
/** * @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; } }
/** * 从结果集中取得一行作为数字索引数组 */ function fetch_row(mysqli_result $query) { return $query->fetch_row(); }
public function fetch_row() { return $this->resource_id->fetch_row(); }
function free() { $this->result->free_result(); }
public function __construct($link, $query) { parent::__construct($link, $query); }