改进查询条件的自动参数绑定

This commit is contained in:
thinkphp
2016-09-13 12:26:22 +08:00
parent 6e96a6aac6
commit 633d0041c6
2 changed files with 37 additions and 16 deletions

View File

@@ -412,13 +412,17 @@ abstract class Connection
{
if ($bind) {
foreach ($bind as $key => $val) {
$val = $this->quote(is_array($val) ? $val[0] : $val);
$value = is_array($val) ? $val[0] : $val;
$type = is_array($val) ? $val[1] : PDO::PARAM_STR;
if (PDO::PARAM_STR == $type) {
$value = $this->quote($value);
}
// 判断占位符
$sql = is_numeric($key) ?
substr_replace($sql, $val, strpos($sql, '?'), 1) :
substr_replace($sql, $value, strpos($sql, '?'), 1) :
str_replace(
[':' . $key . ')', ':' . $key . ',', ':' . $key . ' '],
[$val . ')', $val . ',', $val . ' '],
[$value . ')', $value . ',', $value . ' '],
$sql . ' ');
}
}