The index controller writes the following two methods:
Class Index extends controller{public function Index () { $params = array (' title ' = = ' This is the new record title ', ' Content ' = ' This is a new record ', ' Addtime ' =>date (' y-m-d h:i:s ')); $result = Db::execute (' INSERT into lsf_article (Title,content,addtime) VALUES (: Title,:content,:addtime) ', $params); Sleep (a); $lastid =db::getlastinsid (); echo $lastid; } Public Function test () { $params = array (' title ' = ' = ' This is a new record title2 ', ' content ' = ' This is a new record 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; }}
Open two browsers at the same time, first execute the method index, then execute the method test, the record ID is 50 before execution. The test method is executed first, the value is 52,index 20 seconds after the execution completes, obtains the ID value is 51.
thinkphp get last Insert record ID