From fba2b4b5851481b96532cdd7fc5831a706d871da Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 28 Dec 2017 17:23:33 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=94=B9=E8=BF=9Bmysql=E7=9A=84insertAll?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/builder/Mysql.php | 61 +++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/library/think/db/builder/Mysql.php b/library/think/db/builder/Mysql.php index 5bc9d03b..12b59034 100644 --- a/library/think/db/builder/Mysql.php +++ b/library/think/db/builder/Mysql.php @@ -12,13 +12,72 @@ namespace think\db\builder; use think\db\Builder; +use think\Exception; /** * mysql数据库驱动 */ class Mysql extends Builder { - protected $updateSql = 'UPDATE %TABLE% %JOIN% SET %SET% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%'; + + protected $insertAllSql = '%INSERT% INTO %TABLE% (%FIELD%) VALUES %DATA% %COMMENT%'; + protected $updateSql = 'UPDATE %TABLE% %JOIN% SET %SET% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%'; + + /** + * 生成insertall SQL + * @access public + * @param array $dataSet 数据集 + * @param array $options 表达式 + * @param bool $replace 是否replace + * @return string + * @throws Exception + */ + public function insertAll($dataSet, $options = [], $replace = false) + { + // 获取合法的字段 + if ('*' == $options['field']) { + $fields = array_keys($this->query->getFieldsType($options['table'])); + } else { + $fields = $options['field']; + } + + foreach ($dataSet as $data) { + foreach ($data as $key => $val) { + if (!in_array($key, $fields, true)) { + if ($options['strict']) { + throw new Exception('fields not exists:[' . $key . ']'); + } + unset($data[$key]); + } elseif (is_null($val)) { + $data[$key] = 'NULL'; + } elseif (is_scalar($val)) { + $data[$key] = $this->parseValue($val, $key); + } elseif (is_object($val) && method_exists($val, '__toString')) { + // 对象数据写入 + $data[$key] = $val->__toString(); + } else { + // 过滤掉非标量数据 + unset($data[$key]); + } + } + $value = array_values($data); + $values[] = '( ' . implode(',', $value) . ' )'; + + if (!isset($insertFields)) { + $insertFields = array_map([$this, 'parseKey'], array_keys($data)); + } + } + + return str_replace( + ['%INSERT%', '%TABLE%', '%FIELD%', '%DATA%', '%COMMENT%'], + [ + $replace ? 'REPLACE' : 'INSERT', + $this->parseTable($options['table'], $options), + implode(' , ', $insertFields), + implode(' , ', $values), + $this->parseComment($options['comment']), + ], $this->insertAllSql); + } /** * 字段和表名处理 From ddf4b4b0dcf523978e2460c243a0e42a8a77830d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 29 Dec 2017 17:48:14 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=94=B9=E8=BF=9Bredis=E9=95=BF=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=A4=9A=E7=BC=96=E5=8F=B7=E5=BA=93=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/Redis.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/think/cache/driver/Redis.php b/library/think/cache/driver/Redis.php index a58151f2..93f7ca71 100644 --- a/library/think/cache/driver/Redis.php +++ b/library/think/cache/driver/Redis.php @@ -46,9 +46,12 @@ class Redis extends Driver if (!empty($options)) { $this->options = array_merge($this->options, $options); } - $func = $this->options['persistent'] ? 'pconnect' : 'connect'; $this->handler = new \Redis; - $this->handler->$func($this->options['host'], $this->options['port'], $this->options['timeout']); + if ($this->options['persistent']) { + $this->handler->pconnect($this->options['host'], $this->options['port'], $this->options['timeout'], 'persistent_id_' . $this->options['select']); + } else { + $this->handler->connect($this->options['host'], $this->options['port'], $this->options['timeout']); + } if ('' != $this->options['password']) { $this->handler->auth($this->options['password']); From f264bdfbd84751d7474cac4895a8958fa13d50fe Mon Sep 17 00:00:00 2001 From: phpu Date: Sun, 31 Dec 2017 23:02:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9C=A8=E9=95=BF?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=97=B6=E8=BF=87=E6=9C=9F=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/File.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/cache/driver/File.php b/library/think/cache/driver/File.php index 52243a47..fb857b90 100644 --- a/library/think/cache/driver/File.php +++ b/library/think/cache/driver/File.php @@ -109,7 +109,7 @@ class File extends Driver $content = file_get_contents($filename); if (false !== $content) { $expire = (int) substr($content, 8, 12); - if (0 != $expire && $_SERVER['REQUEST_TIME'] > filemtime($filename) + $expire) { + if (0 != $expire && time() > filemtime($filename) + $expire) { return $default; } $content = substr($content, 32);