當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Query::from方法代碼示例

本文整理匯總了PHP中Cake\Database\Query::from方法的典型用法代碼示例。如果您正苦於以下問題:PHP Query::from方法的具體用法?PHP Query::from怎麽用?PHP Query::from使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\Database\Query的用法示例。


在下文中一共展示了Query::from方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _deleteQueryTranslator

 /**
  * Apply translation steps to delete queries.
  *
  * Chops out aliases on delete query conditions as most database dialects do not
  * support aliases in delete queries. This also removes aliases
  * in table names as they frequently don't work either.
  *
  * We are intentionally not supporting deletes with joins as they have even poorer support.
  *
  * @param \Cake\Database\Query $query The query to translate
  * @return \Cake\Database\Query The modified query
  */
 protected function _deleteQueryTranslator($query)
 {
     $hadAlias = false;
     $tables = [];
     foreach ($query->clause('from') as $alias => $table) {
         if (is_string($alias)) {
             $hadAlias = true;
         }
         $tables[] = $table;
     }
     if ($hadAlias) {
         $query->from($tables, true);
     }
     if (!$hadAlias) {
         return $query;
     }
     $conditions = $query->clause('where');
     if ($conditions) {
         $conditions->traverse(function ($condition) {
             if (!$condition instanceof Comparison) {
                 return $condition;
             }
             $field = $condition->getField();
             if ($field instanceof ExpressionInterface || strpos($field, '.') === false) {
                 return $condition;
             }
             list(, $field) = explode('.', $field);
             $condition->setField($field);
             return $condition;
         });
     }
     return $query;
 }
開發者ID:rlugojr,項目名稱:cakephp,代碼行數:45,代碼來源:SqlDialectTrait.php

示例2: testSelectAliasedFieldsFromTable

 /**
  * Tests it is possible to select aliased fields
  *
  * @return void
  */
 public function testSelectAliasedFieldsFromTable()
 {
     $query = new Query($this->connection);
     $result = $query->select(['text' => 'body', 'author_id'])->from('articles')->execute();
     $this->assertEquals(['text' => 'First Article Body', 'author_id' => 1], $result->fetch('assoc'));
     $this->assertEquals(['text' => 'Second Article Body', 'author_id' => 3], $result->fetch('assoc'));
     $query = new Query($this->connection);
     $result = $query->select(['text' => 'body', 'author' => 'author_id'])->from('articles')->execute();
     $this->assertEquals(['text' => 'First Article Body', 'author' => 1], $result->fetch('assoc'));
     $this->assertEquals(['text' => 'Second Article Body', 'author' => 3], $result->fetch('assoc'));
     $query = new Query($this->connection);
     $query->select(['text' => 'body'])->select(['author_id', 'foo' => 'body']);
     $result = $query->from('articles')->execute();
     $this->assertEquals(['foo' => 'First Article Body', 'text' => 'First Article Body', 'author_id' => 1], $result->fetch('assoc'));
     $this->assertEquals(['foo' => 'Second Article Body', 'text' => 'Second Article Body', 'author_id' => 3], $result->fetch('assoc'));
     $query = new Query($this->connection);
     $exp = $query->newExpr('1 + 1');
     $comp = $query->newExpr(['author_id +' => 2]);
     $result = $query->select(['text' => 'body', 'two' => $exp, 'three' => $comp])->from('articles')->execute();
     $this->assertEquals(['text' => 'First Article Body', 'two' => 2, 'three' => 3], $result->fetch('assoc'));
     $this->assertEquals(['text' => 'Second Article Body', 'two' => 2, 'three' => 5], $result->fetch('assoc'));
 }
開發者ID:KarimaLadhani,項目名稱:cakephp,代碼行數:27,代碼來源:QueryTest.php

示例3: testWhereEmptyValues

 /**
  * Tests that empty values don't set where clauses.
  *
  * @return void
  */
 public function testWhereEmptyValues()
 {
     $query = new Query($this->connection);
     $query->from('comments')->where('');
     $this->assertCount(0, $query->clause('where'));
     $query->where([]);
     $this->assertCount(0, $query->clause('where'));
 }
開發者ID:alexunique0519,項目名稱:Blog_Cakephp_association,代碼行數:13,代碼來源:QueryTest.php


注:本文中的Cake\Database\Query::from方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。