Traits/Think/Model/Query 中的query和execute方法采用参数绑定机制

parseSql方法独立使用 保留原来的预处理机制。
This commit is contained in:
ThinkPHP
2013-04-20 17:11:18 +08:00
parent 5f6cf44f0c
commit 1e4d8c8165

View File

@@ -46,32 +46,22 @@ trait Query {
* SQL查询 * SQL查询
* @access public * @access public
* @param string $sql SQL指令 * @param string $sql SQL指令
* @param mixed $parse 是否需要解析SQL * @param array $bind 参数绑定
* @return mixed * @return mixed
*/ */
public function query($sql,$parse=false) { public function query($sql,$bind=[]) {
if(!is_bool($parse) && !is_array($parse)) { return $this->db->query($sql,$bind);
$parse = func_get_args();
array_shift($parse);
}
$sql = $this->parseSql($sql,$parse);
return $this->db->query($sql);
} }
/** /**
* 执行SQL语句 * 执行SQL语句
* @access public * @access public
* @param string $sql SQL指令 * @param string $sql SQL指令
* @param mixed $parse 是否需要解析SQL * @param array $bind 参数绑定
* @return false | integer * @return false | integer
*/ */
public function execute($sql,$parse=false) { public function execute($sql,$bind=[]) {
if(!is_bool($parse) && !is_array($parse)) { return $this->db->execute($sql,$bind);
$parse = func_get_args();
array_shift($parse);
}
$sql = $this->parseSql($sql,$parse);
return $this->db->execute($sql);
} }
/** /**
@@ -81,7 +71,7 @@ trait Query {
* @param boolean $parse 是否需要解析SQL * @param boolean $parse 是否需要解析SQL
* @return string * @return string
*/ */
protected function parseSql($sql,$parse) { public function parseSql($sql,$parse) {
// 分析表达式 // 分析表达式
if(true === $parse) { if(true === $parse) {
$options = $this->_parseOptions(); $options = $this->_parseOptions();