function DB_common::getCol in Flickr API 5
Fetches a single column from a query result and returns it as an indexed array
Parameters
string $query the SQL query:
mixed $col which column to return (integer [column number,: starting at 0] or string [column name])
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.
Return value
array the results as an array. A DB_Error object on failure.
See also
1 call to DB_common::getCol()
- DB_common::getListOf in phpFlickr/
PEAR/ DB/ common.php - Lists internal database information
File
- phpFlickr/
PEAR/ DB/ common.php, line 1336
Class
- DB_common
- DB_common is the base class from which each database driver class extends
Code
function &getCol($query, $col = 0, $params = []) {
$params = (array) $params;
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 (DB::isError($res)) {
return $res;
}
$fetchmode = is_int($col) ? DB_FETCHMODE_ORDERED : DB_FETCHMODE_ASSOC;
if (!is_array($row = $res
->fetchRow($fetchmode))) {
$ret = array();
}
else {
if (!array_key_exists($col, $row)) {
$ret =& $this
->raiseError(DB_ERROR_NOSUCHFIELD);
}
else {
$ret = array(
$row[$col],
);
while (is_array($row = $res
->fetchRow($fetchmode))) {
$ret[] = $row[$col];
}
}
}
$res
->free();
if (DB::isError($row)) {
$ret = $row;
}
return $ret;
}