From 72cdb44de8b2954b247133b0e2c7c8825a9b288b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Nov 2016 14:32:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bin=E5=92=8Cbetween=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=9D=A1=E4=BB=B6=E7=9A=84=E8=87=AA=E5=8A=A8=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index c963a704..e790cf34 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -333,8 +333,13 @@ abstract class Builder $bind = []; $array = []; foreach ($value as $k => $v) { - $bind[$bindName . '_in_' . $k] = [$v, $bindType]; - $array[] = ':' . $bindName . '_in_' . $k; + if ($this->query->isBind($bindName . '_in_' . $k)) { + $bindKey = $bindName . '_in_' . uniqid() . '_' . $k; + } else { + $bindKey = $bindName . '_in_' . $k; + } + $bind[$bindKey] = [$v, $bindType]; + $array[] = ':' . $bindKey; } $this->query->bind($bind); $zone = implode(',', $array); @@ -347,12 +352,19 @@ abstract class Builder // BETWEEN 查询 $data = is_array($value) ? $value : explode(',', $value); if (array_key_exists($field, $binds)) { + if ($this->query->isBind($bindName . '_between_1')) { + $bindKey1 = $bindName . '_between_1' . uniqid(); + $bindKey2 = $bindName . '_between_2' . uniqid(); + } else { + $bindKey1 = $bindName . '_between_1'; + $bindKey2 = $bindName . '_between_2'; + } $bind = [ - $bindName . '_between_1' => [$data[0], $bindType], - $bindName . '_between_2' => [$data[1], $bindType], + $bindKey1 => [$data[0], $bindType], + $bindKey2 => [$data[1], $bindType], ]; $this->query->bind($bind); - $between = ':' . $bindName . '_between_1' . ' AND :' . $bindName . '_between_2'; + $between = ':' . $bindKey1 . ' AND :' . $bindKey2; } else { $between = $this->parseValue($data[0], $field) . ' AND ' . $this->parseValue($data[1], $field); } @@ -410,7 +422,10 @@ abstract class Builder $info = $type[$key]; } if (isset($info)) { - $value = strtotime($value) ?: $value; + if (is_numeric($value) && strtotime($value)) { + $value = strtotime($value) ?: $value; + } + if (preg_match('/(datetime|timestamp)/is', $info)) { // 日期及时间戳类型 $value = date('Y-m-d H:i:s', $value);