Exemplo n.º 1
0
 public function insertMulti($dataList)
 {
     if (!is_array($dataList) || empty($dataList)) {
         throw new LibraryException('参数错误:$dataList');
     }
     // 自动添加create_time, update_time,前提是这些字段在表中存在并且未传
     $now = time();
     foreach ($dataList as &$data) {
         if (array_key_exists('create_time', $this->fieldTypes) && !array_key_exists('create_time', $data)) {
             $data['create_time'] = $now;
         }
         if (array_key_exists('update_time', $this->fieldTypes) && !array_key_exists('update_time', $data)) {
             $data['update_time'] = $now;
         }
         // 无法插入空行
         if (empty($data)) {
             throw new LibraryException('数据库插入数据不能全部为空!');
         }
     }
     // 插入,返回true或者false
     $sql = $this->sqlBuilder->createInsertSql($dataList);
     $ret = $this->masterHandle->query($sql);
     // 清除该表所有静态缓存
     unset(self::$rowCache[$this->dbName][$this->tableName]);
     return $ret;
 }