Simultaneous access API Rest

Asked

Viewed 158 times

0

I have a PHP application that receives json from another application and writes them to the Mysql database. Before recording the data, I check the database to see if the record has already been previously recorded. However, when I check the database this afternoon, I come across two identical records. What could have happened? Was the client application so fast and before the first was recorded in the bank the second was also being processed? How can I protect myself from that? My Apache configuration is default.

Thank you very much.

1 answer

1


Database managers are able to avoid multiple access. Of course it is possible that after a select an Insert of another query is made. To make it more reliable you can make a select transaction followed by Insert. And another, if two records can’t be the same should be a restriction in the database.

  • Good observation. Now that you spoke, I called in to leave only the registration number. I put the id and forgot the number. About the transaction I didn’t really know I could use with a select and an Insert. Currently I use only in Insert because I write in more than one table. Tomorrow I will complete it early.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.