简体   繁体   中英

Inserting data into multiple tables simultaneously using PHP/MySQL

I have read multiple answers around the site but is still confused about a part of it.

To start with ,I have 2 tables labor_details and labor_contact both of them related using a column labor_id which is primary and auto_incremented.

Now , my plan is to provide a php script to enter data in these tables simultaneously with same labor_id .

One method which i found to work is mysql_insert_id().

But wanted to confirm is- will this method work as expected when multiple users will be entering data simultaneously?

Case 1: At time 0 , User 1 entering Data{insert into labor_details , mysql_insert_id() , insert into labor_contact} User 2 also entering data.{insert into labor_details , mysql_insert_id() , insert into labor_contact}

Will both of them get same ID when they call mysql_insert_id() or a different one.

mysql_insert_id()总是返回最后插入的行,因此,如果有两个用户会话,则在您的情况下,它肯定会返回插入的行id labour_id,它是自动递增的,将为不同的用户返回不同的值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM