Consider a simple schema of one to many relationship. Parent Table's Id is referenced in the Child table.
In php I want to insert a row into the table using the statement mysql_query($query)
. Then I will get the id of the last inserted row by using mysql_insert_id()
. Then i will use this id to insert the another row into the child's table.
My question is that the since there could be multiple requests happening on the same time for a php page, what if the above two statements do NOT run one after the other (ie, for example, there are two inserts happening on the parent and then the two inserts on the child)? There could be concurrency issues. So how do we overcome this?
Any ideas?