PHP + MySql get the ID of the newly added record

Source: Internet
Author: User
PHP + MySql get the ID value of the newly added record 1. assume that the field name is recordID2. the field attribute must be set to auto_increment3. after adding data, use $ newIDmysql_insert_id (); obtain the ID value ASP to obtain the Real-Time ID value ASP + Access20001. the property of the ID value field to be obtained must be set to automatic

PHP + MySql get the ID value of the newly added record 1. assume that the field name is recordID 2. the field attribute must be set to auto_increment 3. after adding data, use $ newID = mysql_insert_id (); obtain the ID value ASP to obtain the Real-Time ID value ASP + Access2000 1. the property of the ID value field to be obtained must be set to automatic

PHP + MySql get the ID of the newly added record

PHP + MySql get the ID of the newly added record

1. Assume that the field name is recordID

2. The field attribute must be set to auto_increment.

3. After adding data, use

$ NewID = mysql_insert_id ();

Obtain the ID value.


ASP get real-time ID value

ASP + Access2000

1. The property of the ID value field to be obtained must be set to: automatic number (we assume that the field name is recordID)

2. Add record format: Rs. Open table, Cn, 1, 3
Note: 1, 3

3. newID = rs. Fields ("recordID ")

4. newID is the ID value of the newly added record.

ASP/SQL Server 2000

1. The property of the ID value field to be obtained must be set to: automatic number (we assume that the field name is recordID)

2. Add record code mode:

Cn. Execute "insert into table (field1, field2,...) VALUES (" field1Value "," field2Value ",...)"

3. Obtain the ID value.

Set Rss = Cn. Execute ("SELECT SCOPE_IDENTITY () as newIDValue FROM table ")
'Rs. Open sqlStr, Cn, 3, 1
NewID = Rss ("newIDValue ")

4. newID is the ID value of the newly added record.

5. Attach three methods to obtain the ID value:

/* It is best to use IDENT_CURRENT ('tbname ')*/
Insert into table (field1, field2,...) VALUES ("field1Value", "field2Value",...) SELECT IDENT_CURRENT ('recordid') as newIDValue

/* Use SCOPE_IDENTITY () for the newly inserted Record ID that is used immediately */
Insert into table (field1, field2,...) VALUES ("field1Value", "field2Value",...) SELECT SCOPE_IDENTITY () as newIDValue

/* It is best to use @ IDENTITY */for the auto-increment ID obtained in a series of operations */
Insert into table (field1, field2,...) VALUES ("field1Value", "field2Value",...) SELECT @ IDENTITY as newIDValu

Original article address: PHP + MySql obtains the ID value of the newly added record. Thank you for sharing it with the original author.

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.