本文整理汇总了PHP中Zend_Db_Select::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db_Select::limit方法的具体用法?PHP Zend_Db_Select::limit怎么用?PHP Zend_Db_Select::limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Db_Select
的用法示例。
在下文中一共展示了Zend_Db_Select::limit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSelect
/**
* Returns the select object to be used for validation.
* @return Zend_Db_Select $select
*/
public function getSelect()
{
if (null === $this->_select) {
$db = $this->getAdapter();
// Zend_Debug::dump($this->_excludeId ); // die(0);
$select = new Zend_Db_Select($db);
$select->from($this->_table, array($this->_field), $this->_schema);
if ($db->supportsParameters('named')) {
$select->where($db->quoteIdentifier($this->_field, true) . ' = :value');
// named
} else {
$select->where($db->quoteIdentifier($this->_field, true) . ' = ?');
// positional
}
$select->limit(1);
if (!empty($this->_meetingId)) {
$select->where($db->quoteInto('`meeting_id` = ?', $this->_meetingId));
}
if (!empty($this->_excludeId)) {
$select->where($db->quoteInto('`id` != ?', $this->_excludeId));
}
$this->_select = $select;
}
return $this->_select;
}
示例2: _query
/**
* Run query and returns matches, or null if no matches are found.
*
* @param String $value
* @return Array when matches are found.
*/
protected function _query($value)
{
/**
* Check for an adapter being defined. if not, fetch the default adapter.
*/
if ($this->_adapter === null) {
$this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
}
/**
* Build select object
*/
$select = new Zend_Db_Select($this->_adapter);
$select->from($this->_table, array($this->_field), $this->_schema)->where($this->_adapter->quoteIdentifier($this->_field) . ' = ?', $value);
if ($this->_exclude !== null) {
if (is_array($this->_exclude)) {
$select->where($this->_adapter->quoteIdentifier($this->_exclude['field']) . ' != ?', $this->_exclude['value']);
} else {
$select->where($this->_exclude);
}
}
$select->limit(1);
/**
* Run query
*/
$result = $this->_adapter->fetchRow($select, array(), Zend_Db::FETCH_ASSOC);
return $result;
}
示例3: getItems
/**
* Returns an array of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage)
{
// Cast to integers, as $itemCountPerPage can be string sometimes and that would fail later checks
$offset = (int) $offset;
$itemCountPerPage = (int) $itemCountPerPage;
if ($this->_lastOffset === $offset && $this->_lastItemCount === $itemCountPerPage && null !== $this->_lastItems) {
return $this->_lastItems;
}
$this->_lastOffset = $offset;
$this->_lastItemCount = $itemCountPerPage;
// Optimization: by using the MySQL feature SQL_CALC_FOUND_ROWS
// we can get the count and the results in a single query.
$db = $this->_select->getAdapter();
if (null === $this->_count && $db instanceof \Zend_Db_Adapter_Mysqli) {
$this->_select->limit($itemCountPerPage, $offset);
$sql = $this->_select->__toString();
if (\MUtil_String::startsWith($sql, 'select ', true)) {
$sql = 'SELECT SQL_CALC_FOUND_ROWS ' . substr($sql, 7);
}
$this->_lastItems = $db->fetchAll($sql);
$this->_count = $db->fetchOne('SELECT FOUND_ROWS()');
} else {
$this->_lastItems = $this->_selectAdapter->getItems($offset, $itemCountPerPage);
}
if (is_array($this->_lastItems)) {
if (isset($this->_model->prefetchIterator) && $this->_model->prefetchIterator) {
$this->_lastItems = new \ArrayIterator($this->_lastItems);
}
$this->_lastItems = $this->_model->processAfterLoad($this->_lastItems, false, false);
}
return $this->_lastItems;
}
示例4: getVesion
function getVesion()
{
$select = new Zend_Db_Select($this->db);
$select->from('Version', 'VersionId');
$select->limit(1);
$res = $this->db->fetchOne($select);
return $res;
}
示例5: limit
public function limit($count = null, $offset = null)
{
if (is_array($count)) {
$offset = $count['start'];
$count = $count['limit'];
}
return parent::limit($count, $offset);
}
示例6: buildQueryLimit
/**
* Set's the query limit
*
* @param int $count Offset Start
* @param int $offset Offset End
*
* @return Zend_Db_Select
*/
public function buildQueryLimit($count, $offset)
{
if ($this->_limit > 0 && $this->_limit < $count) {
$count = $this->_limit;
}
$this->_select->limit($count, $offset);
return $this;
}
示例7: getClientId
function getClientId($client_name)
{
$select = new Zend_Db_Select($this->_db);
$select->from('Client');
$select->where("Name = ?", $client_name);
$select->limit(1);
$stmt = $select->query();
$res = $stmt->fetch();
return $res['clientid'];
}
示例8: search
public function search($word = null, $limit = null)
{
$db = Zend_Registry::get('db');
$sql = new Zend_Db_Select($db);
$select = $sql->from('albums');
if (!is_null($word)) {
$select = $sql->where($db->quoteInto('title LIKE ? OR artist LIKE ?', "%" . $word . "%"));
}
if ($limit > 0) {
$select = $sql->limit($limit);
}
$select = $sql->order('artist DESC');
$results = $db->query($select);
$rows = $results->fetchAll();
return $rows;
}
示例9: fetchRow
/**
* @return array
*/
public function fetchRow()
{
$this->sql_select->limit(1);
return $this->sql_select->query()->fetch();
}
示例10: filterLimitOffset
/**
* Extract limit and offset from the filter and add it to a select
*
* @param array $filter
* @param \Zend_Db_Select $select
*/
protected function filterLimitOffset(&$filter, $select)
{
$limit = null;
$offset = null;
if (array_key_exists('limit', $filter)) {
$limit = (int) $filter['limit'];
unset($filter['limit']);
}
if (array_key_exists('offset', $filter)) {
$offset = (int) $filter['offset'];
unset($filter['offset']);
}
$select->limit($limit, $offset);
}
示例11: fetchRow
/**
* fetchRow wrapper
* This function does not invalidate/store any data on the dataset; All read rows are returned as an array directly
*
* @param string|\Zend_Db_Select $sql
* @param array $params
* @return mixed Array, object, or scalar depending on fetch mode.
*/
public function fetchRow($sql, array $params = [])
{
if ($sql instanceof \Zend_Db_Select) {
$sql->limit(1);
}
$sql = $this->assembleSql($sql);
return $this->getReadAdapter()->fetchRow($sql, $params);
}
示例12: getProduct
public function getProduct($newsDate = null)
{
$start_date = new DateTime();
$start_date->setTime(20, 0, 0);
$start_date->setDate($newsDate->format("Y"), $newsDate->format("m"), $newsDate->format("d") - 1);
$end_date = new DateTime();
$end_date->setTime(10, 0, 0);
$end_date->setDate($newsDate->format("Y"), $newsDate->format("m"), $newsDate->format("d"));
$select = new Zend_Db_Select($this->getDefaultAdapter());
$select->from(array('c' => $this->_campanha));
$select->where('start_date = ?', $start_date->format("Y-m-d H:i:s"));
$select->where('start_date = end_date');
$select->where('is_banner = ?', '0');
$select->where('is_magazine = ?', '0');
$select->where('is_product = ?', '1');
$select->where('is_active = ?', '1');
$select->order("priority DESC");
$select->order("end_date ASC");
$select->limit(1);
return $this->_db->fetchAssoc($select);
}
示例13: _query
/**
* Overrides _query() from Zend_Validate_Db_Abstract
*
* @param mixed $value
* @access protected
* @return void
*/
protected function _query($value)
{
if ($this->_adapter === NULL) {
$this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
if (NULL === $this->_adapter) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('No database adapter present');
}
}
$select = new Zend_Db_Select($this->_adapter);
$select->from($this->_table, array($this->_field), $this->_schema);
if (NULL == $this->_userPkValue) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('You must specify the value for the primary / unique key');
}
$select->where($this->_adapter->quoteIdentifier($this->_userPkField) . ' = ?', $this->_userPkValue);
if (strpos($this->_treatment, '?') !== FALSE || $this->_treatment instanceof Zend_Db_Expr) {
$where = $this->_adapter->quoteIdentifier($this->_field) . ' = ' . $this->_treatment;
$select->where($where, $value);
} else {
$value = call_user_func($this->_treatment, $value);
$select->where($this->_adapter->quoteIdentifier($this->_field) . ' = ?', $value);
}
$select->limit(1);
$result = $this->_adapter->fetchRow($select, array(), Zend_Db::FETCH_ASSOC);
return $result;
}
示例14: _refineSelection
/**
* Refine the active pastes selection based on criteria provided
*
* Allows setting a limit to the number of records returend
*
* @param Zend_Db_Select $select
* @param array $criteria
* @return void
*/
protected function _refineSelection(Zend_Db_Select $select, array $criteria)
{
if (array_key_exists('start', $criteria) && $criteria['start'] == intval($criteria['start'])) {
if (array_key_exists('count', $criteria) && $criteria['count'] == intval($criteria['count'])) {
$select->limit($criteria['count'], $criteria['start']);
}
}
$sorted = false;
if (array_key_exists('sort', $criteria)) {
$sort = $criteria['sort'];
$dir = 'ASC';
if ('-' == substr($sort, 0, 1)) {
$sort = substr($sort, 1);
$dir = 'DESC';
}
$fields = $this->getTable()->info('cols');
if (in_array($sort, $fields)) {
$select->order("{$sort} {$dir}");
$sorted = true;
}
}
if (!$sorted) {
$select->order('created DESC');
}
}
示例15: getSelect
/**
* Gets the select object to be used by the validator.
* If no select object was supplied to the constructor,
* then it will auto-generate one from the given table,
* schema, field, and adapter options.
*
* @return Zend_Db_Select The Select object which will be used
*/
public function getSelect()
{
if (null === $this->_select) {
$db = $this->getAdapter();
/**
* Build select object
*/
$select = new Zend_Db_Select($db);
$select->from($this->_table, array($this->_field), $this->_schema);
if ($db->supportsParameters('named')) {
$select->where($db->quoteIdentifier($this->_field, true) . ' = :value');
// named
} else {
$select->where($db->quoteIdentifier($this->_field, true) . ' = ?');
// positional
}
if ($this->_exclude !== null) {
if (is_array($this->_exclude)) {
$select->where($db->quoteIdentifier($this->_exclude['field'], true) . ' != ?', $this->_exclude['value']);
} else {
$select->where($this->_exclude);
}
}
$select->limit(1);
$this->_select = $select;
}
return $this->_select;
}