$database->count = "SELECT * FROM table WHERE item_id = 1"
if($database->count == 1)
{
$database->update = "UPDATE users SET money = money - 1000";
$database->delete = "DELETE table WHERE item_id = 1";
}
Let’s say I have this code (I’ve just created it) in index.php page. Can at the same time "SELECT * FROM table WHERE item_id = 1" query happen so two people would get count 1 and -1000 money? If yes, how can I avoid that?
Thank you.
If you’re worried about two queries running at the same time being responsible for unbalanced state in your DB, you should be using transactions : http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-transactions.html
Transactions are helpful in keeping the state of your data correct.