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


PHP Query::execute方法代码示例

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


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

示例1: testInsertExpressionValues

 /**
  * Test that insert can use expression objects as values.
  *
  * @return void
  */
 public function testInsertExpressionValues()
 {
     $query = new Query($this->connection);
     $query->insert(['title', 'author_id'])->into('articles')->values(['title' => $query->newExpr("SELECT 'jose'"), 'author_id' => 99]);
     $result = $query->execute();
     $result->closeCursor();
     //PDO_SQLSRV returns -1 for successful inserts when using INSERT ... OUTPUT
     if (!$this->connection->driver() instanceof \Cake\Database\Driver\Sqlserver) {
         $this->assertCount(1, $result);
     }
     $result = (new Query($this->connection))->select('*')->from('articles')->where(['author_id' => 99])->execute();
     $this->assertCount(1, $result);
     $expected = ['id' => 4, 'title' => 'jose', 'body' => null, 'author_id' => '99', 'published' => 'N'];
     $this->assertEquals($expected, $result->fetch('assoc'));
     $subquery = new Query($this->connection);
     $subquery->select(['name'])->from('authors')->where(['id' => 1]);
     $query = new Query($this->connection);
     $query->insert(['title', 'author_id'])->into('articles')->values(['title' => $subquery, 'author_id' => 100]);
     $result = $query->execute();
     $result->closeCursor();
     //PDO_SQLSRV returns -1 for successful inserts when using INSERT ... OUTPUT
     if (!$this->connection->driver() instanceof \Cake\Database\Driver\Sqlserver) {
         $this->assertCount(1, $result);
     }
     $result = (new Query($this->connection))->select('*')->from('articles')->where(['author_id' => 100])->execute();
     $this->assertCount(1, $result);
     $expected = ['id' => 5, 'title' => 'mariano', 'body' => null, 'author_id' => '100', 'published' => 'N'];
     $this->assertEquals($expected, $result->fetch('assoc'));
 }
开发者ID:KarimaLadhani,项目名称:cakephp,代码行数:34,代码来源:QueryTest.php

示例2: execute

 /**
  * {@inheritDoc}
  */
 public function execute()
 {
     $this->_transformQuery();
     return parent::execute();
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:8,代码来源:Query.php

示例3: testUnionAll

 /**
  * Tests that UNION ALL can be built by setting the second param of union() to true
  *
  * @return void
  */
 public function testUnionAll()
 {
     $union = (new Query($this->connection))->select(['id', 'title'])->from(['a' => 'articles']);
     $query = new Query($this->connection);
     $result = $query->select(['id', FunctionsBuilder::toChar(new IdentifierExpression('comment'))])->from(['c' => 'comments'])->union($union)->execute();
     $rows = $result->fetchAll();
     $this->assertCount(self::ARTICLE_COUNT + self::COMMENT_COUNT, $rows);
     $union->select(['foo' => 'id', 'bar' => 'title']);
     $union = (new Query($this->connection))->select(['id', 'name', 'other' => 'id', 'nameish' => 'name'])->from(['b' => 'authors'])->where(['id ' => 1]);
     $query->select(['foo' => 'id', 'bar' => FunctionsBuilder::toChar(new IdentifierExpression('comment'))])->unionAll($union);
     $result = $query->execute();
     $rows2 = $result->fetchAll();
     $this->assertCount(1 + self::COMMENT_COUNT + self::ARTICLE_COUNT, $rows2);
     $this->assertNotEquals($rows, $rows2);
 }
开发者ID:cakedc,项目名称:cakephp-oracle-driver,代码行数:20,代码来源:QueryTest.php

示例4: testBetweenExpressionAndTypeMap

 /**
  * Tests that types in the type map are used in the
  * specific comparison functions when using a callable
  *
  * @return void
  */
 public function testBetweenExpressionAndTypeMap()
 {
     $this->loadFixtures('Comments');
     $query = new Query($this->connection);
     $query->select('id')->from('comments')->defaultTypes(['created' => 'datetime'])->where(function ($expr) {
         $from = new \DateTime('2007-03-18 10:45:00');
         $to = new \DateTime('2007-03-18 10:48:00');
         return $expr->between('created', $from, $to);
     });
     $this->assertCount(2, $query->execute()->fetchAll());
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:17,代码来源:QueryTest.php

示例5: testInsertFromSelect

 /**
  * Test that INSERT INTO ... SELECT works.
  *
  * @return void
  */
 public function testInsertFromSelect()
 {
     $select = (new Query($this->connection))->select(['name', "'some text'", 99])->from('authors')->where(['id' => 1]);
     $query = new Query($this->connection);
     $query->insert(['title', 'body', 'author_id'], ['title' => 'string', 'body' => 'string', 'author_id' => 'integer'])->into('articles')->values($select);
     $result = $query->sql();
     $this->assertQuotedQuery('INSERT INTO <articles> \\(<title>, <body>, <author_id>\\) SELECT', $result, true);
     $this->assertQuotedQuery('SELECT <name>, \'some text\', 99 FROM <authors>', $result, true);
     $result = $query->execute();
     $this->assertCount(1, $result);
     $result = (new Query($this->connection))->select('*')->from('articles')->where(['author_id' => 99])->execute();
     $this->assertCount(1, $result);
     $expected = ['id' => 4, 'title' => 'mariano', 'body' => 'some text', 'author_id' => 99, 'published' => 'N'];
     $this->assertEquals($expected, $result->fetch('assoc'));
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:20,代码来源:QueryTest.php

示例6: testInsertExpressionValues

 /**
  * Test that insert can use expression objects as values.
  *
  * @return void
  */
 public function testInsertExpressionValues()
 {
     $query = new Query($this->connection);
     $query->insert(['title'])->into('articles')->values(['title' => $query->newExpr("SELECT 'jose'")]);
     $result = $query->execute();
     $this->assertCount(1, $result);
     $subquery = new Query($this->connection);
     $subquery->select(['name'])->from('authors')->where(['id' => 1]);
     $query = new Query($this->connection);
     $query->insert(['title'])->into('articles')->values(['title' => $subquery]);
     $result = $query->execute();
     $this->assertCount(1, $result);
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:18,代码来源:QueryTest.php


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