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


PHP SelectQuery::sql方法代码示例

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


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

示例1: testSubqueryWithConditions

 /**
  * testing nested subquery (query, which uses subquery, which uses subquery) and checking, that conditions are correct (for use in prepared queries)
  */
 public function testSubqueryWithConditions()
 {
     $field1 = new Field('id', 0);
     $subq2 = new SelectQuery(array('bans'));
     $subq2->setSelect(array($field1));
     $subq2->setWhere(new Condition('=', new Field('abc'), 10));
     $subq = new SelectQuery(array('users'));
     $subq->setSelect(array($field1));
     $subq->setWhere(new AndOp(new Condition('>', new Field('age'), 14), new Condition('in', new Field('id'), $subq2), new Condition('=', new Field('regdt'), '2009-01-01')));
     $q = new SelectQuery(array('posts'));
     $q->setWhere(new AndOp(new Condition('>', new Field('comment'), 1), new Condition('in', new Field('user_id'), $subq), new Condition('=', new Field('funny'), 1)));
     $this->assertEquals('SELECT `t0`.* FROM `posts` AS `t0` WHERE (`t0`.`comment` > :p1 AND `t0`.`user_id` IN (SELECT `t0`.`id` FROM `users` AS `t0` WHERE (`t0`.`age` > :p2 AND `t0`.`id` IN (SELECT `t0`.`id` FROM `bans` AS `t0` WHERE `t0`.`abc` = :p3) AND `t0`.`regdt` = :p4)) AND `t0`.`funny` = :p5)', $q->sql());
 }
开发者ID:NinjaKC,项目名称:MySQL-Query-Builder,代码行数:16,代码来源:SelectQueryTest.php

示例2: testSqlFunctions

 public function testSqlFunctions()
 {
     $f = new SqlFunction('substring', array(new Field('name'), 5, 2));
     $params = array();
     $this->assertEquals('SUBSTRING(`t0`.`name`, 5, 2)', $f->getSql($params));
     $this->assertEquals('substring', $f->getName());
     try {
         $f = new SqlFunction('there_is_no_such_function', new Field('name'));
         $this->fail();
     } catch (InvalidArgumentException $e) {
     }
     try {
         $f = new SqlFunction('substring', new AndOp(array()));
         $this->fail('wrong value accepted');
     } catch (InvalidArgumentException $e) {
     }
     $q = new SelectQuery('test');
     $q->setWhere(new Condition('>', new SqlFunction('length', new Field('foo')), 5));
     $params = array();
     $this->assertEquals('SELECT `t0`.* FROM `test` AS `t0` WHERE LENGTH(`t0`.`foo`) > :p1', $q->sql());
     $parameters = $q->parameters();
     $this->assertEquals('5', $parameters[':p1']);
 }
开发者ID:NinjaKC,项目名称:MySQL-Query-Builder,代码行数:23,代码来源:OtherTest.php


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