春华秋衣
oracle主键log_id 不能自动递增有两个办法:1、使用oracle的自动增长序列创建序列
create sequence S_T_THINK_LOG
increment by 1 //指定序列以1递增,如果没指定,默认值1会使用
start with 1 //由1开始计数
nomaxvalue //不设置最大值
minvalue 1 //设置最小值1
cache 20 //预分配缓存大小为20
order
// 获取下一个自增ID
public function getNextSeq(){
$sql = "select S_T_THINK_LOG.nextval id from sys.dual";
$result = $this->query($sql);
$nextId = $result[0]['id'];
return $nextId;
}
function writelog($uid,$username,$description,$status)
{
// 注意这里啦
// 注意这里啦
$data['log_id'] = $this->getNextSeq();
$data['admin_id'] = $uid;
$data['admin_name'] = $username;
$data['description'] = $description;
$data['status'] = $status;
$data['ip'] = request()->ip();
$data['add_time'] = time();
$log = Db::name('think_log')->insert($data);
}
第二种,就是楼上说的 触发器啦
create or replace trigger trg_TINK_LOG
before insert on TINK_LOG
for each row
declare
begin
:think_log.LOG_ID:= S_T_THINK_LOG.NEXTVAL;
end trg_t1;