本文整理汇总了PHP中PDOStatement::fetchColumn方法的典型用法代码示例。如果您正苦于以下问题:PHP PDOStatement::fetchColumn方法的具体用法?PHP PDOStatement::fetchColumn怎么用?PHP PDOStatement::fetchColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDOStatement
的用法示例。
在下文中一共展示了PDOStatement::fetchColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lock
/**
* Tries to aquire a lock for job $id and returns, whether it was succesful.
*
* @param integer $id
* @return bool
*/
public function lock($id)
{
$this->lock = self::LOCKPREFIX . $id;
if (!$this->lockStmt) {
$q = $this->db->createSelectQuery();
$q->select('GET_LOCK( ' . $q->bindParam($this->lock) . ', 0 )');
$this->lockStmt = $q->prepare();
}
$this->lockStmt->execute();
$result = $this->lockStmt->fetchColumn();
if ('1' === $result) {
return TRUE;
}
if ('0' === $result) {
$this->lock = null;
return FALSE;
}
throw new Exception($result);
}
示例2: getExchangeRate
/**
* {@inheritdoc}
*/
public function getExchangeRate($sourceCurrencyCode, $targetCurrencyCode)
{
$this->statement->execute([$sourceCurrencyCode, $targetCurrencyCode]);
$exchangeRate = $this->statement->fetchColumn();
if ($exchangeRate === false) {
throw CurrencyConversionException::exchangeRateNotAvailable($sourceCurrencyCode, $targetCurrencyCode);
}
return $exchangeRate;
}
示例3: found_rows
/** SELECT FOUND_ROWS() after query with SQL_CALC_FOUND_ROWS
* @return int
*/
public function found_rows()
{
if (is_null($this->_fr_stmt)) {
$this->_fr_stmt = $this->prepare('SELECT FOUND_ROWS();');
}
$this->_fr_stmt->execute();
$rows_count = $this->_fr_stmt->fetchColumn(0);
$this->_fr_stmt->closeCursor();
return $rows_count;
}
示例4: value
/**
* Get value from table row
*
* @param string $sql SQL-query
* @param array $params Query values
* @param string|null $types Placeholders types
*
* @return mixed
*/
public function value($sql, array $params, $types)
{
$result = '';
try {
$this->prepare($sql, $params, $types);
$result = $this->stmt->fetchColumn();
} catch (\PDOException $e) {
$this->throwExceptionWithInfo($sql, $params, $e);
}
return $result;
}
示例5: getTile
/**
* For every tile needed, this function will be called
*
* Return the blob of this image
* @param Tile $tile
* @throws TileNotAvailableException
* @return string Blob of this image
*/
public function getTile(Tile $tile)
{
$this->tile_fetcher->bindValue(':x', $tile->x);
$this->tile_fetcher->bindValue(':y', $tile->y);
$this->tile_fetcher->execute();
$tile_data = $this->tile_fetcher->fetchColumn();
if ($tile_data === false) {
throw new TileNotAvailableException();
}
return $tile_data;
}
示例6: fetchOne
/**
* 获取单个属性值
* 由于该方法会造成安全问题,所以不建议使用。在必须使用的场合,需要程序人员对sql语句做严格验证
* @param string $sql 预处理执行的sql
* @param array $data 符合pdo预处理模式键值对
* @return string
* @deprecated since version 108
*/
public function fetchOne($sql, $data = null)
{
$this->execute($sql, $data);
$data = $this->stmt instanceof \PDOStatement ? $this->stmt->fetchColumn() : FALSE;
$this->stmt = null;
return $data;
}
示例7: query_result
/**
* Get result data.
* @param int The row number from the result that's being retrieved. Row numbers start at 0.
* @param int The offset of the field being retrieved.
* @return array|false The contents of one cell from a MySQL result set on success, or false on failure.
*/
public function query_result($row, $field = 0)
{
if ($row > 1) {
$this->result->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT, $row);
}
return $this->result->fetchColumn($field);
}
示例8: fetchColumn
/**
* Fetches ony column only
*
* If rows have already been fetched, this method will throw an exception.
* Once used, you cannot use other fetch methods.
*
* @param int $columnIndex
* @return mixed
*/
public function fetchColumn($columnIndex = 0)
{
$this->_index++;
if (isset($this->_rows[$this->_index])) {
return $this->_rows[$this->_index];
}
if ($this->_statement !== null) {
if (!$this->_fetchColumnLock && count($this->_rows)) {
throw new Atomik_Db_Query_Exception('Atomik_Db_Query_Result cannot fetch only columns when full rows have already been fetched');
}
if (($value = $this->_statement->fetchColumn($columnIndex)) === false) {
$this->_statement = null;
return false;
}
$this->_fetchColumnLock = true;
$this->_rows[$this->_index] = $value;
return $value;
}
return false;
}
示例9: fetchColumn
/**
* 通过字段编号获取单条数据的单个字段值
*
* 默认获取的是第一个字段
*
* @param int $columnNumber
* @throws \HuiLib\Error\Exception
* @return array|object
*/
public function fetchColumn($columnNumber = 0)
{
if ($this->innerStatment == NULL) {
throw new \HuiLib\Error\Exception('fetchColumn须先调用Query::query');
}
return $this->innerStatment->fetchColumn($columnNumber);
}
示例10: getCount
/**
* Получить все записи результата
*
* @return mixed
*/
public function getCount()
{
$this->selectColumns(array('count' => 'count(*)'))->execute();
$rez = (int) $this->_srcQueryObj->fetchColumn();
$this->clearParamsQuery();
return $rez;
}
示例11: findColumn
/**
* @return string|null
*/
public function findColumn()
{
if ($this->execute()) {
return $this->statement->fetchColumn();
}
return null;
}
示例12: fetchColumnAll
/**
* Returns a column from all rows of the resultset.
*
* @param int $columnNumber The number of the column in the row (zero indexed).
*
* @return array A simple 1 dimension array which stores the required columns value from every row.
*/
public function fetchColumnAll($columnNumber = 0)
{
$result = array();
while (($columnValue = $this->statement->fetchColumn($columnNumber)) !== false) {
$result[] = $columnValue;
}
return $result;
}
示例13: fetchColumn
/**
* 从下一行记录中获得下标是$index的值,如果获取失败则返回false
*
* @param int $index 列下标
* @return string|bool
*/
public function fetchColumn($index = 0)
{
$result = $this->_statement->fetchColumn($index);
if (WIND_DEBUG & 2) {
Wind::getApp()->getComponent('windLogger')->info("[component.db.WindResultSet.fetchColumn] \r\n\tResult:" . WindString::varToString($result));
}
return $result;
}
示例14: fetchColumn
/**
* Returns a single column from a row in the current pdo select
* statement. The pointer is then advanced to the next row. Returns null
* when reaching the end of the result stack.
*
* The default column returned is the first. The column number may be changed
* to return a different column result.
*
* @param integer $column
* @return string
*/
public function fetchColumn($column = 0)
{
$this->checkStatement();
$result = $this->pdo_statement->fetchColumn($column);
if (empty($result)) {
$this->clearStatement();
}
return $result;
}
示例15: fetchColumn
/**
* Returns a single column from the next row of a result set.
*
* @param int $col OPTIONAL Position of the column to fetch.
* @return string
* @throws Zend_Db_Statement_Exception
*/
public function fetchColumn($col = 0)
{
try {
return $this->_stmt->fetchColumn($col);
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage());
}
}