thinkphp get last Insert record ID

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.