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


PHP Query::having方法代码示例

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


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

示例1: testSelectHaving

 /**
  * Tests that having() behaves pretty much the same as the where() method
  *
  * @return void
  */
 public function testSelectHaving()
 {
     $query = new Query($this->connection);
     $result = $query->select(['total' => 'count(author_id)', 'author_id'])->from('articles')->join(['table' => 'authors', 'alias' => 'a', 'conditions' => 'author_id = a.id'])->group('author_id')->having(['count(author_id) <' => 2], ['count(author_id)' => 'integer'])->execute();
     $expected = [['total' => 1, 'author_id' => 3]];
     $this->assertEquals($expected, $result->fetchAll('assoc'));
     $result = $query->having(['count(author_id)' => 2], ['count(author_id)' => 'integer'], true)->execute();
     $expected = [['total' => 2, 'author_id' => 1]];
     $this->assertEquals($expected, $result->fetchAll('assoc'));
     $result = $query->having(function ($e) {
         return $e->add('count(author_id) = 1 + 1');
     }, [], true)->execute();
     $expected = [['total' => 2, 'author_id' => 1]];
     $this->assertEquals($expected, $result->fetchAll('assoc'));
 }
开发者ID:KarimaLadhani,项目名称:cakephp,代码行数:20,代码来源:QueryTest.php


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