Skip to content
This repository was archived by the owner on Jan 4, 2020. It is now read-only.

Commit 8d8e002

Browse files
committed
修正数据库参数绑定一处BUG
1 parent f31631e commit 8d8e002

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

ThinkPHP/Library/Think/Db/Driver.class.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,11 @@ protected function parseSet($data)
414414
} elseif (is_scalar($val)) {
415415
// 过滤非标量数据
416416
if (0 === strpos($val, ':') && in_array($val, array_keys($this->bind))) {
417-
$set[] = $this->parseKey($key) . '=' . $this->escapeString($val);
417+
$set[] = $this->parseKey($key) . '=' . $val;
418418
} else {
419419
$name = count($this->bind);
420-
$set[] = $this->parseKey($key) . '=:' . $name;
421-
$this->bindParam($name, $val);
420+
$set[] = $this->parseKey($key) . '=:' . $key . '_' . $name;
421+
$this->bindParam($key . '_' . $name, $val);
422422
}
423423
}
424424
}
@@ -443,7 +443,7 @@ protected function bindParam($name, $value)
443443
* @param string $key
444444
* @return string
445445
*/
446-
protected function parseKey(&$key)
446+
protected function parseKey($key)
447447
{
448448
return $key;
449449
}
@@ -522,8 +522,7 @@ protected function parseTable($tables)
522522
}
523523
$tables = $array;
524524
} elseif (is_string($tables)) {
525-
$tables = explode(',', $tables);
526-
array_walk($tables, array(&$this, 'parseKey'));
525+
$tables = array_map(array($this, 'parseKey'), explode(',', $tables));
527526
}
528527
return implode(',', $tables);
529528
}
@@ -909,11 +908,11 @@ public function insert($data, $options = array(), $replace = false)
909908
// 过滤非标量数据
910909
$fields[] = $this->parseKey($key);
911910
if (0 === strpos($val, ':') && in_array($val, array_keys($this->bind))) {
912-
$values[] = $this->parseValue($val);
911+
$values[] = $val;
913912
} else {
914913
$name = count($this->bind);
915-
$values[] = ':' . $name;
916-
$this->bindParam($name, $val);
914+
$values[] = ':' . $key . '_' . $name;
915+
$this->bindParam($key . '_' . $name, $val);
917916
}
918917
}
919918
}
@@ -982,8 +981,8 @@ public function selectInsert($fields, $table, $options = array())
982981
$fields = explode(',', $fields);
983982
}
984983

985-
array_walk($fields, array($this, 'parseKey'));
986-
$sql = 'INSERT INTO ' . $this->parseTable($table) . ' (' . implode(',', $fields) . ') ';
984+
$fields = array_map(array($this, 'parseKey'), $fields);
985+
$sql = 'INSERT INTO ' . $this->parseTable($table) . ' (' . implode(',', $fields) . ') ';
987986
$sql .= $this->buildSelectSql($options);
988987
return $this->execute($sql, !empty($options['fetch_sql']) ? true : false);
989988
}

ThinkPHP/Library/Think/Db/Driver/Mysql.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function getTables($dbName = '')
9898
* @param string $key
9999
* @return string
100100
*/
101-
protected function parseKey(&$key)
101+
protected function parseKey($key)
102102
{
103103
$key = trim($key);
104104
if (!is_numeric($key) && !preg_match('/[,\'\"\*\(\)`.\s]/', $key)) {
@@ -197,10 +197,10 @@ protected function parseDuplicate($duplicate)
197197
}
198198

199199
switch ($val[0]) {
200-
case 'exp': // 表达式
200+
case 'exp': // 表达式
201201
$updates[] = $this->parseKey($key) . "=($val[1])";
202202
break;
203-
case 'value': // 值
203+
case 'value':// 值
204204
default:
205205
$name = count($this->bind);
206206
$updates[] = $this->parseKey($key) . "=:" . $name;

ThinkPHP/Library/Think/Db/Driver/Sqlsrv.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected function parseOrder($order)
109109
* @param string $key
110110
* @return string
111111
*/
112-
protected function parseKey(&$key)
112+
protected function parseKey($key)
113113
{
114114
$key = trim($key);
115115
if (!is_numeric($key) && !preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) {

0 commit comments

Comments
 (0)