本文整理汇总了PHP中Zend_Db::fetchOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db::fetchOne方法的具体用法?PHP Zend_Db::fetchOne怎么用?PHP Zend_Db::fetchOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Db
的用法示例。
在下文中一共展示了Zend_Db::fetchOne方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setup
/**
* Creates and populates the DataSource
*
* @access public
* @return void
**/
public function setup()
{
$select = $this->getSelect();
if ($this->paginate) {
$sql = $this->getSelectCountSql();
$this->totalRows = (int) $this->_db->fetchOne($sql);
list($start, $total) = $this->limit;
$select->reset(Zend_Db_Select::LIMIT_COUNT);
$select->reset(Zend_Db_Select::LIMIT_OFFSET);
$select->limit($total, $start);
} else {
$this->totalRows = 0;
}
$select->reset(Zend_Db_Select::ORDER);
if (count($this->order) > 0) {
$select->order($this->order);
}
// Fetch Select Columns
$rawColumns = $select->getPart(Zend_Db_Select::COLUMNS);
$columns = array();
// Get columns and Force casting as strings
foreach ($rawColumns as $col) {
$columns[] = (string) $col[1];
}
$this->cols = $columns;
$this->totalColumns = count($columns);
// Fetch
$stmt = $this->_db->query($select);
$rows = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
$total = count($rows);
$this->totalRowset = $total;
$this->rows = $rows;
}
示例2: count
/**
* Implements countable, returns count of records
*/
public function count()
{
if ($this->_count !== false) {
return $this->_count;
}
// Originally, we chose to replace the selected fields part of the query with a COUNT(*), however
// we ran into several conditions where this would not work such as if the query has a join, a limit,
// a group by, a sub-select as a field, or orders by a derived field. Therefore, we do a sub-select
// of our own to find the count.
$this->_count = (int) $this->_zendDb->fetchOne('SELECT COUNT(*) as rowCount FROM (' . $this->query() . ') as t1');
return $this->_count;
}