当前位置: 首页>>代码示例>>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;未经允许,请勿转载。