Home >php教程 >php手册 >tp2.2支持子查询

tp2.2支持子查询

WBOY
WBOYOriginal
2016-06-07 11:45:291634browse

使tp2.2支持子查询,比较上线的项目 没办法总升级框架....tp3.0以下不能用子查询 比较无语了 更改后使用方法和tp3.0一样
更改/ThinkPHP/Lib/Think/Db/Db.class.php和/ThinkPHP/Lib/Think/Core/Model.class.php

懒人给了压缩包 tp2.1和2.2通用
直接解压到/ThinkPHP/Lib/Think/Core 目录下


Model.class.php select函数改为public function select($options=array()) {<br>         if(is_string($options) || is_numeric($options)) {<br>             // 根据主键查询<br>             $pk   =  $this->getPk();<br>             if(strpos($options,',')) {<br>                 $where[$pk] =  array('IN',$options);<br>             }else{<br>                 $where[$pk]   =  $options;<br>             }<br>             $options =  array();<br>             $options['where'] =  $where;<br>         }elseif(false === $options){<br>             $options =  array();<br>             // 分析表达式<br>             $options =  $this->_parseOptions($options);<br>             return  '( '.$this->db->buildSelectSql($options).' )';<br>         }<br>         // 分析表达式<br>         $options =  $this->_parseOptions($options);<br>         $resultSet = $this->db->select($options);<br>         if(false === $resultSet) {<br>             return false;<br>         }<br>         if(empty($resultSet)) { // 查询结果为空<br>             return null;<br>         }<br>         $this->_after_select($resultSet,$options);<br>         return $resultSet;<br>     }Db.class.php parseTable函数改为protected function parseTable($tables) {<br>         if(is_array($tables)) {// 支持别名定义<br>             $array   =  array();<br>             foreach ($tables as $table=>$alias){<br>                 if(!is_numeric($table))<br>                     $array[] =  $this->parseKey($table).' '.$this->parseKey($alias);<br>                 else<br>                     $array[] =  $this->parseKey($table);<br>             }<br>             $tables  =  $array;<br>         }elseif(is_string($tables)){<br>             $tables  =  explode(',',$tables);<br>             //array_walk($tables, array(&$this, 'parseKey'));//支持子查询 取消过滤<br>         }<br>         return implode(',',$tables);<br>     }

附件 Core.zip ( 16.2 KB 下载:143 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:令牌验证函数单独拿出来Next article:仿百度分页类