有二个表格分别为thead和posts,一个类似留言板的设计,(discuz,phpwind里边也是相同名字的表)thead
tid auto_increment primary key,
time int,
..........posts
pid auto_increment primary key,
tid int,
time int,
.....现在就是,在thead表里边插入一行数据后,要得到自动增长的thead.tid的值,然后把thead.tid的值插入到posts表格里的posts.tid里边,有没有好的方法实现这个??目前能想到的只有,,:注$phpvar为php端生成的时间戳
lock table thead;
insert into thead(tid,time,...) value(null,$phpvar,)
set @AA=last_insert_id(); ///这里或者select @AA:=tid from thead where time=$phpvar;
insert into post(pid,tid,...) value(null,@AA,...);
unlock tables
tid auto_increment primary key,
time int,
..........posts
pid auto_increment primary key,
tid int,
time int,
.....现在就是,在thead表里边插入一行数据后,要得到自动增长的thead.tid的值,然后把thead.tid的值插入到posts表格里的posts.tid里边,有没有好的方法实现这个??目前能想到的只有,,:注$phpvar为php端生成的时间戳
lock table thead;
insert into thead(tid,time,...) value(null,$phpvar,)
set @AA=last_insert_id(); ///这里或者select @AA:=tid from thead where time=$phpvar;
insert into post(pid,tid,...) value(null,@AA,...);
unlock tables
insert into post(pid,tid,...) value(null,last_insert_id(),...);