改进条件查询的参数绑定 支持 单个字段的多个条件查询

This commit is contained in:
thinkphp
2016-09-13 15:38:29 +08:00
parent 942aa65c2d
commit c676ff56cc

View File

@@ -260,7 +260,7 @@ abstract class Builder
}
// where子单元分析
protected function parseWhereItem($field, $val, $rule = '', $options = [], $binds = [])
protected function parseWhereItem($field, $val, $rule = '', $options = [], $binds = [], $bindName = null)
{
// 字段分析
$key = $field ? $this->parseKey($field) : '';
@@ -280,8 +280,9 @@ abstract class Builder
} else {
array_push($val, $item);
}
foreach ($val as $item) {
$str[] = $this->parseWhereItem($field, $item, $rule, $options, $binds);
foreach ($val as $k => $item) {
$bindName = 'where_' . $field . '_' . $k;
$str[] = $this->parseWhereItem($field, $item, $rule, $options, $binds, $bindName);
}
return '( ' . implode(' ' . $rule . ' ', $str) . ' )';
}
@@ -298,8 +299,9 @@ abstract class Builder
$bindType = isset($binds[$field]) ? $binds[$field] : PDO::PARAM_STR;
if (is_scalar($value) && array_key_exists($field, $binds) && !in_array($exp, ['IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN']) && strpos($exp, 'TIME') === false) {
if (strpos($value, ':') !== 0 || !$this->query->isBind(substr($value, 1))) {
$this->query->bind('where_' . $field, $value, $bindType);
$value = ':where_' . $field;
$bindName = $bindName ?: 'where_' . $field;
$this->query->bind($bindName, $value, $bindType);
$value = ':' . $bindName;
}
}