From e41120dcbfd9801b12b075ee1020aab159429c47 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 2 May 2016 14:24:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=A8=A1=E5=9E=8B=E7=B1=BB?= =?UTF-8?q?=E7=9A=84saveAll=E6=96=B9=E6=B3=95=20db=E5=8A=A9=E6=89=8B?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=A2=9E=E5=8A=A0name=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 7 ++++--- library/think/Model.php | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/helper.php b/helper.php index 5b4df203..374fb0a6 100644 --- a/helper.php +++ b/helper.php @@ -152,12 +152,13 @@ function model($name = '', $layer = MODEL_LAYER) /** * 实例化数据库类 - * @param array $config 数据库配置参数 + * @param string $name 操作的数据表名称(不含前缀) + * @param array|string $config 数据库配置参数 * @return \think\db\Connection */ -function db($config = []) +function db($name = '', $config = []) { - return Db::connect($config); + return Db::connect($config)->name($name); } /** diff --git a/library/think/Model.php b/library/think/Model.php index e7b5dcf3..d9ad7794 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -205,9 +205,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @access public * @param array $data 数据 * @param array $where 更新条件 + * @param bool $getId 新增的时候是否获取id * @return integer */ - public function save($data = [], $where = []) + public function save($data = [], $where = [], $getId = true) { if (!empty($data)) { // 数据对象赋值 @@ -270,7 +271,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $result = self::db()->insert($this->data); // 获取自动增长主键 - if ($result) { + if ($result && $getId) { $insertId = self::db()->getLastInsID(); $pk = $this->getPk(); if (is_string($pk) && $insertId) {