From 8985a41c323ccb13957fc76ce1d81040efe4c3f8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 4 Jan 2017 16:50:42 +0800 Subject: [PATCH] =?UTF-8?q?like=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 12 +++++++++++- library/think/db/Query.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 29b5688a..2372152c 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -334,9 +334,19 @@ abstract class Builder } $whereStr = ''; - if (in_array($exp, ['=', '<>', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE'])) { + if (in_array($exp, ['=', '<>', '>', '>=', '<', '<='])) { // 比较运算 及 模糊匹配 $whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value, $field); + } elseif ('LIKE' == $exp || 'NOT LIKE' == $exp) { + if (is_array($value)) { + foreach ($value as $item) { + $array[] = $key . ' ' . $exp . ' ' . $this->parseValue($item, $field); + } + $logic = isset($val[2]) ? $val[2] : 'AND'; + $whereStr .= '(' . implode($array, ' ' . strtoupper($logic) . ' ') . ')'; + } else { + $whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value, $field); + } } elseif ('EXP' == $exp) { // 表达式查询 $whereStr .= '( ' . $key . ' ' . $value . ' )'; diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 21c70a03..263565f9 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1018,7 +1018,7 @@ class Query // 字段相等查询 $where[$field] = ['eq', $op]; } else { - $where[$field] = [$op, $condition]; + $where[$field] = [$op, $condition, isset($param[2]) ? $param[2] : null]; if ('exp' == strtolower($op) && isset($param[2]) && is_array($param[2])) { // 参数绑定 $this->bind($param[2]);