获取添加数据的自增ID】的更多相关文章

$id= DB::select("select auto_increment from information_schema.`TABLES` where table_name='student' and TABLE_SCHEMA='monthexe'");…
指定字段: $historyinfo = Healthy::find()->select(['healthy_id','pet_name','hardware_name','hardware_color','remove_binding'])->where(['user_id'=>$user_id,'is_activation'=>'2'])->asArray()->all(); 获取添加数据的id:  $id = $model->attributes['heal…
调用游标下的lastrowid 可以获取插入之前的表里id字段存放到哪个自增id cursor.lastrowid mysql> select * from userinfo; +----+-------+-----+ | id | name | pwd | +----+-------+-----+ | 1 | mike | 123 | | 2 | jack | 456 | | 3 | alex | 555 | | 4 | peter | 989 | | 5 | app | 123 | | 6…
一.情景引入 项目需求:对于一个数据表(表A)的增.删.改全部要有日志记录,日志表(表B)结构 中需要记录表A的自增ID,这样才能将日志与操作的数据一一对应起来. 对于删和改都好办,获取Model时都可以取到这个自增ID,然后就可以存入日志表,但是如果新增一条数据,应该如何获取到这个自增ID呢?不知道我有没有表达清楚,下面直接贴具体代码吧: 二.项目代码 string sql="";//这里写你的具体的新增语句INSERT....... strSql.Append(sql); strS…
<insert id="save" parameterType="Vote" useGeneratedKeys="true" keyProperty="id"> INSERT INTO vote VALUES(null,#{theme},#{isuse}) <selectKey resultType="int" order="AFTER" keyProperty=&qu…
SCOPE_IDENTITY()函数 返回的是紧跟这个插入语句生成的自增ID, 若果前一个语句不是插入自增ID的,将返回NULL @@IDENTITY 返回全局的最有一个生成的自增ID,全局可用 create table test( id int identity ,v int ) insert into test(v)values(1) select SCOPE_IDENTITY() SELECT @@IDENTITY 结果 Note 有的地方喜欢使用 output inserted.tab_…
<insert id="save" parameterType="Vote" useGeneratedKeys="true" keyProperty="id"> INSERT INTO vote VALUES(null,#{theme},#{isuse}) <selectKey resultType="int" order="AFTER" keyProperty=&qu…
//插入一条数据 $sql = "INSERT INTO `table_name` (`name`,age) VALUES ('小明','23')"; $dsql->SetQuery($sql);//格式化查询语句 $dsql->ExecNoneQuery();//执行SQL操作 $lastInsertID = $dsql->GetLastID(); //获取插入后的最后的ID…
创建表格时添加: create table table1(id int auto_increment primary key,...) 创建表格后添加: 删除原有主键: ALTER TABLE `table_name` DROP `id`; alter table table1 add id int auto_increment primary key 自增字段,一定要设置为primary key. 例子 alter table tablename drop column id; ) not n…
Yii::$app->db->createCommand()->insert('month4_user',['openid'=>$openid,'integ'=>0])->execute(); $id=Yii::$app->db->getLastInsertID(); var_dump($id);…