I have written a game in php which uses a small mysql database. There are small prizes available which are detailed in the database, once a prize has been won, the prize is removed from the database. I was posed the question; would it be possible for two people to win the same prize if they clicked the exactly the same time? I explained that php processes pages in milliseconds and that the chances are billions to one. Being realistic, what are the chances of a php page being executed which pulls the same mysql results at exactly the same time?
SQL queries are put into ques, so when two queries need to be run at the same time they are qued so the first one in the que would make the second one error. Prob won't impress the second person if they thought they had won though.
So, when php runs mysql_query, mysql then puts that into a queue, then returns to php once complete ?
Yeah, it is way to fast for your to notice it. But thats why websites with thousands of users running sql slow down. It's cause the queries are qued. It is done to avoid exactly the problem you suggested.