当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::limit方法代码示例

本文整理汇总了PHP中Cake\Database\Query::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::limit方法的具体用法?PHP Query::limit怎么用?PHP Query::limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Database\Query的用法示例。


在下文中一共展示了Query::limit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findCursor

 public function findCursor(Query $query)
 {
     $current = $this->request->query('cursor');
     $limit = $this->request->query('limit') ?: 10;
     if ($current) {
         $query->where(['id >' => $current]);
     }
     $query->limit($limit);
     return $query;
 }
开发者ID:cakeplugins,项目名称:api,代码行数:10,代码来源:CursorHelperBehavior.php

示例2: testSelectOffset

 /**
  * Tests selecting rows combining a limit and offset clause
  *
  * @return void
  */
 public function testSelectOffset()
 {
     $query = new Query($this->connection);
     $result = $query->select('id')->from('comments')->limit(1)->offset(0)->order(['id' => 'ASC'])->execute();
     $this->assertCount(1, $result);
     $this->assertEquals(['id' => 1], $result->fetch('assoc'));
     $query = new Query($this->connection);
     $result = $query->select('id')->from('comments')->limit(1)->offset(1)->execute();
     $this->assertCount(1, $result);
     $this->assertEquals(['id' => 2], $result->fetch('assoc'));
     $query = new Query($this->connection);
     $result = $query->select('id')->from('comments')->limit(1)->offset(2)->execute();
     $this->assertCount(1, $result);
     $this->assertEquals(['id' => 3], $result->fetch('assoc'));
     $query = new Query($this->connection);
     $result = $query->select('id')->from('articles')->order(['id' => 'DESC'])->limit(1)->offset(0)->execute();
     $this->assertCount(1, $result);
     $this->assertEquals(['id' => 3], $result->fetch('assoc'));
     $result = $query->limit(2)->offset(1)->execute();
     $this->assertCount(2, $result);
     $this->assertEquals(['id' => 2], $result->fetch('assoc'));
     $this->assertEquals(['id' => 1], $result->fetch('assoc'));
 }
开发者ID:KarimaLadhani,项目名称:cakephp,代码行数:28,代码来源:QueryTest.php

示例3: testSelectOffset

 /**
  * Tests selecting rows combining a limit and offset clause
  *
  * @return void
  */
 public function testSelectOffset()
 {
     $this->loadFixtures('Articles', 'Comments');
     $query = new Query($this->connection);
     $result = $query->select('id')->from('comments')->limit(1)->offset(0)->order(['id' => 'ASC'])->execute();
     $this->assertCount(1, $result);
     $this->assertEquals(['id' => 1], $result->fetch('assoc'));
     $query = new Query($this->connection);
     $result = $query->select('id')->from('comments')->limit(1)->offset(1)->execute();
     $this->assertCount(1, $result);
     $this->assertEquals(['id' => 2], $result->fetch('assoc'));
     $query = new Query($this->connection);
     $result = $query->select('id')->from('comments')->limit(1)->offset(2)->execute();
     $this->assertCount(1, $result);
     $this->assertEquals(['id' => 3], $result->fetch('assoc'));
     $query = new Query($this->connection);
     $result = $query->select('id')->from('articles')->order(['id' => 'DESC'])->limit(1)->offset(0)->execute();
     $this->assertCount(1, $result);
     $this->assertEquals(['id' => 3], $result->fetch('assoc'));
     $result = $query->limit(2)->offset(1)->execute();
     $this->assertCount(2, $result);
     $this->assertEquals(['id' => 2], $result->fetch('assoc'));
     $this->assertEquals(['id' => 1], $result->fetch('assoc'));
     $query = new Query($this->connection);
     $query->select('id')->from('comments')->limit(1)->offset(1)->execute();
     $dirty = $this->readAttribute($query, '_dirty');
     $this->assertFalse($dirty);
     $query->offset(2);
     $dirty = $this->readAttribute($query, '_dirty');
     $this->assertTrue($dirty);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:36,代码来源:QueryTest.php


注:本文中的Cake\Database\Query::limit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。