Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat happens when a PHP script accesses a MySQL database at the same time, more than once?
    primarykey
    data
    text
    <p>I was curious about how PHP scripts and MySQL behave? The script is basically two SQL queries.</p> <p>The first SELECTs and gets a number from a column of a specific row decided by some id.</p> <p>Then if the number is positive the second UPDATES the column by subtracting a certain amount.</p> <p>Obviously this a classic case where I would use transactions or lock or mutexes or what on.</p> <p><strong>My questions is this:</strong> In a website it is entirely possible for two or more users to call the script at the same time for the same row. If you don't use transactions or lock tables how will PHP process this? They are two queries/function calls but they are in one script. Does it wait the whole script to return to it's corresponding user to run it again for another user or because they are different queries because of pseudoparallelism it might run the first query on multiple user calling the same script and then the second for a different set..</p> <p>Basically I am asking because I am doing something where I don't have enough permissions to use transaction or locks and I want to know if I can a avoid a mutex (I am not sure about the word, basically a new table for callers; before calling the script above I will call a new script before that where I will turn the boolean column of the table true for writing so other people cant while the original script finishes and afterwards bacl to false so the next in line can do and so on)</p> <p><strong>Edit:</strong> I am not sure about select for update whether the permissions for that are included in the above mentioned. The guy responsible for answering my questions is hard to find and I ve had it with me searching for him...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload