"Go" PHP last Insert ID

Source: Internet
Author: User
Tags mysql connect
Call MySQL in PHP, built-in last_insert_id () This function may not be used by anyone, the most used or mysql_insert_id ()

In fact, these two are different, last_insert_id () can return the ID of the bigint value. Instead, MYSQL_INSERT_ID returns an int. If you

The ID of the unsigned int, or bigint. Then, it may be that the error is returned. Instead of using last_insert_id ()

Some friends, return is 0, do not know how, in fact, last_insert_id () returned is the ID of auto_increment.

If, in the table structure, there is no setting, auto_increment cannot return.

There are others, or return to 0. Then you'll have to check to see if you're using the Insert delay function. In this case, the immediate return ID value is not returned.

Many people like to use SELECT Max (ID) ... To replace this last_insert_id, in fact, select MAX (ID) is non-thread safe, and it is possible that

Other threads have inserted new data and you can't find the ID you last inserted. and last_insert_id is corresponding to a MySQL connect, which is

Corresponds to your current line threads and will not be disturbed by other threads. If there are some strange errors in your database, for example, to update the information of a data,

The result B data is updated, and is sometimes correct, sometimes incorrect, and when people are too many, they are very incorrect. We'll see if we're using select Max (ID).

Http://www.jb51.net/article/21063.htm

  • 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.