index控制器下写如下两个方法:
class Index extends Controller{ ???public function index() ???{ ???????????$params = array(‘title‘=>‘这是新增记录title‘,‘content‘=>‘这是新增记录内容‘,‘addtime‘=>date(‘Y-m-d H:i:s‘)); ???????$result = Db::execute(‘insert into lsf_article(title,content,addtime) values(:title,:content,:addtime)‘,$params); ???????sleep(20); ???????$lastid=Db::getLastInsID(); ???????echo $lastid; ???} ???public function test(){ ???????$params = array(‘title‘=>‘这是新增记录title2‘,‘content‘=>‘这是新增记录内容2‘,‘addtime‘=>date(‘Y-m-d H:i:s‘)); ???????$result = Db::execute(‘insert into lsf_article(title,content,addtime) values(:title,:content,:addtime)‘,$params); ???????$lastid=Db::getLastInsID(); ???????echo $lastid; ???}}
同时打开两个浏览器,首先执行方法index,接着再执行方法test,执行前记录ID为50。test方法先执行完毕,值为52,index方法20秒钟后执行完毕,获得ID值为51.
thinkphp获得最后一条插入记录ID
原文地址:http://www.cnblogs.com/asdef/p/7656222.html