當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。