function DB_common::getAll in Flickr API 5
Fetches all of the rows from a query result
Parameters
string $query the SQL query:
mixed $params array, string or numeric data to be used in: execution of the statement. Quantity of items passed must match quantity of placeholders in query: meaning 1 placeholder for non-array parameters or 1 placeholder per array element.
int $fetchmode the fetch mode to use:: + DB_FETCHMODE_ORDERED + DB_FETCHMODE_ASSOC + DB_FETCHMODE_ORDERED | DB_FETCHMODE_FLIPPED + DB_FETCHMODE_ASSOC | DB_FETCHMODE_FLIPPED
Return value
array the nested array. A DB_Error object on failure.
File
- phpFlickr/
PEAR/ DB/ common.php, line 1578
Class
- DB_common
- DB_common is the base class from which each database driver class extends
Code
function &getAll($query, $params = [], $fetchmode = DB_FETCHMODE_DEFAULT) {
// compat check, the params and fetchmode parameters used to
// have the opposite order
if (!is_array($params)) {
if (is_array($fetchmode)) {
if ($params === null) {
$tmp = DB_FETCHMODE_DEFAULT;
}
else {
$tmp = $params;
}
$params = $fetchmode;
$fetchmode = $tmp;
}
elseif ($params !== null) {
$fetchmode = $params;
$params = array();
}
}
if (sizeof($params) > 0) {
$sth = $this
->prepare($query);
if (DB::isError($sth)) {
return $sth;
}
$res =& $this
->execute($sth, $params);
$this
->freePrepared($sth);
}
else {
$res =& $this
->query($query);
}
if ($res === DB_OK || DB::isError($res)) {
return $res;
}
$results = array();
while (DB_OK === $res
->fetchInto($row, $fetchmode)) {
if ($fetchmode & DB_FETCHMODE_FLIPPED) {
foreach ($row as $key => $val) {
$results[$key][] = $val;
}
}
else {
$results[] = $row;
}
}
$res
->free();
if (DB::isError($row)) {
$tmp =& $this
->raiseError($row);
return $tmp;
}
return $results;
}