本文整理汇总了PHP中resource::fetchArray方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::fetchArray方法的具体用法?PHP resource::fetchArray怎么用?PHP resource::fetchArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource::fetchArray方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* Load a value from cache.
*
* @param string $id
* @param string $time
* @return mixed
*/
public function load($id, $time)
{
$value = false;
// Determine if the value already exists.
$rows = [];
$this->prepare("SELECT * FROM " . $this->table . " WHERE id = :id")->bindParams(['id' => sha1($id)])->execute();
if ($this->isPdo) {
while (($row = $this->result->fetchAll(\PDO::FETCH_ASSOC)) != false) {
$rows[] = $row;
}
} else {
while (($row = $this->result->fetchArray(SQLITE3_ASSOC)) != false) {
$rows[] = $row;
}
}
// If the value is found, check expiration and return.
if (count($rows) > 0) {
$data = $rows[0]['value'];
$timestamp = $rows[0]['time'];
if ($timestamp == 0 || time() - $timestamp <= $time) {
$value = unserialize($data);
}
}
return $value;
}
示例2: count
/**
* Get the number of rows in the result set
*
* @return int
*/
public function count()
{
switch ($this->mode) {
case "mysql":
$rows = $this->result->num_rows;
break;
case "postgres":
case "redshift":
$rows = pg_num_rows($this->result);
break;
case "odbc":
$rows = odbc_num_rows($this->result);
# The above function is unreliable, so if we got a zero count then double check it
if ($rows < 1) {
$rows = 0;
/**
* If it is an update/delete then we just have to trust the odbc_num_rows() result,
* however it is some kind of select, then we can manually count the rows returned.
*/
if (odbc_num_fields($this->result) > 0) {
$position = $this->position;
$this->seek(0);
while ($this->getNextRow()) {
++$rows;
}
$this->seek($position);
}
}
break;
case "sqlite":
$rows = 0;
while ($this->result->fetchArray()) {
$rows++;
}
$this->seek($this->position);
break;
case "mssql":
$rows = mssql_num_rows($this->result);
break;
}
if ($rows === false || $rows < 0) {
throw new \Exception("Failed to get the row count from the result set");
}
return $rows;
}
示例3: getLifetime
/**
* Get the lifetime of the value.
*
* @param string $id
* @return int
*/
public function getLifetime($id)
{
// Determine if the value already exists.
$rows = [];
$value = 0;
$this->prepare('SELECT * FROM "' . $this->table . '" WHERE "id" = :id')->bindParams(['id' => sha1($id)])->execute();
if ($this->isPdo) {
while (($row = $this->result->fetchAll(\PDO::FETCH_ASSOC)) != false) {
$rows[] = $row;
}
} else {
while (($row = $this->result->fetchArray(SQLITE3_ASSOC)) != false) {
$rows[] = $row;
}
}
// If the value is found, check expiration and return.
if (count($rows) > 0) {
$cacheValue = $rows[0];
$value = $cacheValue['lifetime'];
}
return $value;
}
示例4: _fetch
/**
* Fetch an array from a database result set
*
* @param resource $res
* @return array
*/
protected function _fetch($res)
{
return $res->fetchArray(SQLITE3_ASSOC);
}
示例5: fetchAll
/**
* Fetches a complete result as an object
*
* @param resource $result Resultset
*
* @throws Exception
*
* @return array of stdClass
*/
public function fetchAll($result)
{
$ret = array();
if (false === $result) {
throw new Exception('Error while fetching result: ' . $this->error());
}
$result->fetchedByPMF = true;
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$ret[] = (object) $row;
}
return $ret;
}
示例6: copyTable
/**
* Copies the contents of from_table in the first database into the
* to a to_table of suitable schema in a second database. It assumes the
* table exists in both databases
*
* @param string $from_table name of the table to be copied from
* @param resource $from_dbm database resource for the from table
* @param resource $to_table name of the table to be copied to
* @param resource $to_dbm database resource for the to table
*/
static function copyTable($from_table, $from_dbm, $to_table, $to_dbm)
{
$sql = "SELECT * FROM {$from_table}";
if (($result = $from_dbm->execute($sql)) === false) {
return false;
}
while ($row = $from_dbm->fetchArray($result)) {
$statement = "INSERT INTO {$to_table} VALUES (";
$comma = "";
foreach ($row as $col => $value) {
$statement .= $comma . " '" . $to_dbm->escapeString($value) . "'";
$comma = ",";
}
$statement .= ")";
if ($to_dbm->execute($statement) === false) {
return false;
}
}
return true;
}
示例7: nextRecord
public function nextRecord()
{
// Coalesce rather than replace common fields.
if ($data = @$this->handle->fetchArray(SQLITE3_NUM)) {
foreach ($data as $columnIdx => $value) {
if (preg_match('/^"([a-z0-9_]+)"\\."([a-z0-9_]+)"$/i', $this->handle->columnName($columnIdx), $matches)) {
$columnName = $matches[2];
} else {
if (preg_match('/^"([a-z0-9_]+)"$/i', $this->handle->columnName($columnIdx), $matches)) {
$columnName = $matches[1];
} else {
$columnName = trim($this->handle->columnName($columnIdx), "\"' \t");
}
}
// $value || !$ouput[$columnName] means that the *last* occurring value is shown
// !$ouput[$columnName] means that the *first* occurring value is shown
if (isset($value) || !isset($output[$columnName])) {
$output[$columnName] = is_null($value) ? null : (string) $value;
}
}
return $output;
} else {
return false;
}
}
示例8: fetchAll
/**
* Returns an array containing all of the result set rows
*
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
* This value must be one of the Doctrine_Core::FETCH_* constants,
* defaulting to Doctrine_Core::FETCH_BOTH
*
* @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
* Doctrine_Core::FETCH_COLUMN. Defaults to 0.
*
* @return array
*/
public function fetchAll($fetchStyle = Doctrine_Core::FETCH_BOTH, $colnum = 0)
{
return $this->connection->fetchArray($this->result, $fetchStyle);
}
示例9: nextRecord
public function nextRecord()
{
if ($data = $this->handle->fetchArray(SQLITE3_ASSOC)) {
return $data;
} else {
return false;
}
}