修正PDO参数绑定的一处BUG

This commit is contained in:
thinkphp
2016-01-20 19:13:03 +08:00
parent a17080244e
commit 6d8191d63c
6 changed files with 12 additions and 18 deletions

View File

@@ -178,11 +178,6 @@ class View
$replace = $this->config['parse_str']; $replace = $this->config['parse_str'];
$content = str_replace(array_keys($replace), array_values($replace), $content); $content = str_replace(array_keys($replace), array_values($replace), $content);
} }
if (APP_DEBUG && $this->config['parse_var']) {
// debug模式时将后台分配变量输出到浏览器控制台
$parseVar = empty($vars) ? json_encode([]) : json_encode($vars);
$content .= '<script type="text/javascript">var __VAR__ = ' . $parseVar . ';</script>';
}
return $content; return $content;
} }

View File

@@ -432,8 +432,8 @@ abstract class Driver
$set[] = $this->parseKey($key) . '=' . $val; $set[] = $this->parseKey($key) . '=' . $val;
} else { } else {
$name = count($this->bind); $name = count($this->bind);
$set[] = $this->parseKey($key) . '=:' . $name; $set[] = $this->parseKey($key) . '=:' . $key . '_' . $name;
$this->bindParam($name, $val); $this->bindParam($key . '_' . $name, $val);
} }
} }
} }
@@ -458,7 +458,7 @@ abstract class Driver
* @param string $key * @param string $key
* @return string * @return string
*/ */
protected function parseKey(&$key) protected function parseKey($key)
{ {
return $key; return $key;
} }
@@ -539,8 +539,7 @@ abstract class Driver
} }
$tables = $array; $tables = $array;
} elseif (is_string($tables)) { } elseif (is_string($tables)) {
$tables = explode(',', $tables); $tables = array_map([$this, 'parseKey'], explode(',', $tables));
array_walk($tables, [ & $this, 'parseKey']);
} }
return implode(',', $tables); return implode(',', $tables);
} }
@@ -913,8 +912,8 @@ abstract class Driver
$values[] = $val; $values[] = $val;
} else { } else {
$name = count($this->bind); $name = count($this->bind);
$values[] = ':' . $name; $values[] = ':' . $key . '_' . $name;
$this->bindParam($name, $val); $this->bindParam($key . '_' . $name, $val);
} }
} }
} }
@@ -983,8 +982,8 @@ abstract class Driver
$fields = explode(',', $fields); $fields = explode(',', $fields);
} }
array_walk($fields, [$this, 'parseKey']); $fields = array_map([$this, 'parseKey'], $fields);
$sql = 'INSERT INTO ' . $this->parseTable($table) . ' (' . implode(',', $fields) . ') '; $sql = 'INSERT INTO ' . $this->parseTable($table) . ' (' . implode(',', $fields) . ') ';
$sql .= $this->buildSelectSql($options); $sql .= $this->buildSelectSql($options);
return $this->execute($sql, !empty($options['fetch_sql']) ? true : false); return $this->execute($sql, !empty($options['fetch_sql']) ? true : false);
} }

View File

@@ -90,7 +90,7 @@ class Mysql extends Driver
* @param string $key * @param string $key
* @return string * @return string
*/ */
protected function parseKey(&$key) protected function parseKey($key)
{ {
$key = trim($key); $key = trim($key);
if (strpos($key, '$.') && false === strpos($key, '(')) { if (strpos($key, '$.') && false === strpos($key, '(')) {

View File

@@ -179,7 +179,7 @@ class Oracle extends Driver
* @param string $key * @param string $key
* @return string * @return string
*/ */
protected function parseKey(&$key) protected function parseKey($key)
{ {
$key = trim($key); $key = trim($key);
if (strpos($key, '$.') && false === strpos($key, '(')) { if (strpos($key, '$.') && false === strpos($key, '(')) {

View File

@@ -100,7 +100,7 @@ class Pgsql extends Driver
* @param string $key * @param string $key
* @return string * @return string
*/ */
protected function parseKey(&$key) protected function parseKey($key)
{ {
$key = trim($key); $key = trim($key);
if (strpos($key, '$.') && false === strpos($key, '(')) { if (strpos($key, '$.') && false === strpos($key, '(')) {

View File

@@ -108,7 +108,7 @@ class Sqlsrv extends Driver
* @param string $key * @param string $key
* @return string * @return string
*/ */
protected function parseKey(&$key) protected function parseKey($key)
{ {
$key = trim($key); $key = trim($key);
if (!preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) { if (!preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) {