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


PHP Select::toQuery方法代码示例

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


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

示例1: toQuery

 /**
  * Render sql query
  * [<sql>, {<params>}]
  * @return array
  */
 public function toQuery()
 {
     $params = array();
     $columns = $this->renderColumns($this->fromColumns, $this->fromAlias, $params);
     $fromParams = array();
     if ($this->fromTable instanceof Select) {
         list($query, $params) = $this->fromTable->toQuery();
         $from = 'FROM (' . $query . ') AS ' . $this->fromAlias . PHP_EOL;
         $fromParams = $params;
     } else {
         $from = 'FROM ' . $this->fromTable . ' AS ' . $this->fromAlias . PHP_EOL;
     }
     foreach ($this->join as $join) {
         list($type, $table, $alias, $on, $joinColumns) = $join;
         /** @var $table Select */
         if ($table instanceof self) {
             list($joinSelect, $joinParams) = $table->toQuery();
             $table = '(' . $joinSelect . ')';
             $fromParams = array_merge($fromParams, $joinParams);
         }
         $from .= $type . ' ' . $table . ' AS ' . $alias;
         if ($on) {
             $from .= ' ON ( ' . $on . ' )';
         }
         $from .= PHP_EOL;
         $columns = array_merge($columns, $this->renderColumns($joinColumns, $alias, $params));
     }
     $where = $this->renderCondition($this->where, $params);
     $having = $this->renderCondition($this->having, $params);
     $group = $this->renderOrder($this->group, $params);
     $order = $this->renderOrder($this->order, $params);
     $sql = 'SELECT ';
     if ($this->isDistinct) {
         $sql .= 'DISTINCT ';
     }
     $sql .= join(', ', $columns) . PHP_EOL;
     $sql .= $from;
     if ($where) {
         $sql .= 'WHERE ' . $where . PHP_EOL;
     }
     if ($group) {
         $sql .= 'GROUP BY ' . $group . PHP_EOL;
     }
     if ($having) {
         $sql .= 'HAVING ' . $having;
     }
     if ($order) {
         $sql .= 'ORDER BY ' . $order . PHP_EOL;
     }
     $sql .= $this->renderLimit($this->limit, $this->offset);
     $params = array_merge($params, $fromParams);
     return array($sql, $params);
 }
开发者ID:mitallast,项目名称:php-db,代码行数:58,代码来源:Select.php

示例2: whereNotExists

 /**
  * @param Select $select
  * @return static
  */
 public function whereNotExists(Select $select)
 {
     list($query, $params) = $select->toQuery();
     return $this->where('NOT EXISTS (' . $query . ')', $params);
 }
开发者ID:mitallast,项目名称:php-db,代码行数:9,代码来源:ConditionQuery.php


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