本文整理匯總了PHP中mysqli::fetch方法的典型用法代碼示例。如果您正苦於以下問題:PHP mysqli::fetch方法的具體用法?PHP mysqli::fetch怎麽用?PHP mysqli::fetch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mysqli
的用法示例。
在下文中一共展示了mysqli::fetch方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: loadDataFromMysqliStatement
/**
* Mysqli's binding and returning of statement values
* Mysqli requires you to bind variables to the extension in order to
* get data out. These values have to be references:
*
* @see http://php.net/manual/en/mysqli-stmt.bind-result.php
* @throws Exception\RuntimeException
* @return bool
*/
protected function loadDataFromMysqliStatement()
{
$data = null;
// build the default reference based bind structure, if it does not already exist
if ($this->statementBindValues['keys'] === null) {
$this->statementBindValues['keys'] = array();
/* @var $resultResource \mysqli_result */
$resultResource = $this->resource->result_metadata();
foreach ($resultResource->fetch_fields() as $col) {
$this->statementBindValues['keys'][] = $col->name;
}
$this->statementBindValues['values'] = array_fill(0, count($this->statementBindValues['keys']), null);
$refs = array();
foreach ($this->statementBindValues['values'] as $i => &$f) {
$refs[$i] =& $f;
}
call_user_func_array(array($this->resource, 'bind_result'), $this->statementBindValues['values']);
}
if (($r = $this->resource->fetch()) === null) {
if (!$this->isBuffered) {
$this->resource->close();
}
return false;
} elseif ($r === false) {
throw new Exception\RuntimeException($this->resource->error);
}
// dereference
for ($i = 0, $count = count($this->statementBindValues['keys']); $i < $count; $i++) {
$this->currentData[$this->statementBindValues['keys'][$i]] = $this->statementBindValues['values'][$i];
}
$this->currentComplete = true;
$this->nextComplete = true;
$this->position++;
return true;
}
示例2: create_table_PDO
/**
* @param mysqli $result le pasamos el resultado de la consulta de la base de datos realizada con PDO.
* @param array $col_names, array de strings que tiene como valor por defecto un array vacio, si está vacio los nombres de las columnas serán los nombres de las columnas de la base de datos, si queremos darles nombres mas representativos podemos rellenar este campo (ej['nombre','apellido','email'])
* @return string $table devuelve el string formado que contiene la tabla.
*/
function create_table_PDO($result, $col_names = array())
{
$table = '';
$rows = array();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
array_push($rows, $row);
}
$table .= '<table>';
$table .= '<tr>';
if (count($col_names) !== 0) {
for ($i = 0; $i < count($col_names); $i++) {
$table .= '<th>' . $col_names[$i] . '</th>';
}
} else {
foreach ($rows as $row) {
$count = 0;
foreach ($row as $key => $value) {
$table .= ' <th>' . $key . '</th>';
if ($count > count($row)) {
break;
}
$count++;
}
break;
}
}
$table .= '</tr>';
foreach ($rows as $row) {
$table .= '<tr>';
foreach ($row as $key => $value) {
$table .= ' <td>' . $value . '</td>';
}
$table .= '</tr>';
}
$table .= '</table>';
return $table;
}