Doubts of the mysql_insert_id

Source: Internet
Author: User
MYSQL_INSERT_ID's question

CREATE TABLE ' create_id ' (
' id ' int (ten) unsigned not NULL auto_increment COMMENT ' generate Auto-increment user_id ',
' V ' varchar (1) Not NULL COMMENT ' is used to generate a new ID ',
PRIMARY KEY (' id '),
UNIQUE KEY ' V ' (' V ')
) Engine=myisam DEFAULT Charset=utf8;

Replace into ' create_id ' set ' V ' = ' 1 ';

After executing this SQL, the Insert ID cannot be obtained with mysql_insert_id. What method/function can get the new ID generated by replace into?
------Solution--------------------
The replace directive may or may not produce a new ID
So it's normal to get it.

So what is the method/function that can get the new ID generated by replace into?
The answer is no, but you can specify the ID
------Solution--------------------
Select last_insert_id () as ' ID ' from ' create_id ';
With
Select id from ' create_id ' ORDER BY id DESC LIMIT 1
Isn't it the same?
------Solution--------------------
Reference:
Select last_insert_id () as ' ID ' from ' create_id ';
With
Select id from ' create_id ' ORDER BY id DESC LIMIT 1
Isn't it the same?


In case of concurrency, ORDER BY id DESC may be someone else's ID.
is last_insert_id () within the scope of a database connection?
------Solution--------------------
Originally this can also get ID, learn the
------Solution--------------------
Select ID from TB ORDER BY id DESC LIMIT 1
------Solution--------------------
Reference:
Select ID from TB ORDER BY id DESC LIMIT 1
This can only get the ID inside the library, right? The landlord is when inserting data, to get the current ID.
I used TP to write:
$Form =m (' member ');
$sql = "Show table status where Name= ' Fht_member '";
$rs = $Form->query ($sql);
$Mid = $rs [0][' auto_increment '];
The return recordset has a [' auto_increment '], which is the currently inserted self-increment ID
  • 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.