I am wondering if it is necessary for data consistency concerns to use locks for none-persistent connections to MYSQL server. While performing changes to tables accessed by multiple users at the same time. To illustrate more I will use a scenario that I am working with.
Lets's assume I am using PDO and manual transactions with beginTransaction()
and commit()
, and I am doing a simple INSERT INTO TABLE
query. The table has a Primary key and it is auto-incremented. I am interested to reuse The ID column of the inserted row after insertion, with help of lastInsertId();
To create another Insert withing the same transaction and use the ID as a value in another table
Do I have to use table locks to prevent data inconstancy? If so what is a good practice of doing that?