Ethan Allen
Ethan Allen

Reputation: 14835

Are calls using mysql_query() in PHP 5 asynchronous?

Here's some sample DB code:

mysql_query("DELETE FROM table1 WHERE info1 = 'blah'");
mysql_query($personal_query);

Theoretically, could the second line get executed before the first line has completed the DELETE? If so, how do I make the code NOT asynchronous? I need to ensure that the DELETE is completed before moving on. Would just getting a return value solve this?

$result = mysql_query("DELETE FROM table1 WHERE info1 = 'blah'");
mysql_query($personal_query);

Thanks.

Upvotes: 0

Views: 511

Answers (2)

tereško
tereško

Reputation: 58444

What you are looking for is a way to lock either the row or the whole table. This should help: http://dev.mysql.com/doc/refman/5.5/en/locking-issues.html

You have to keep in mind that so called "race conditions" usually apply, when two or more users are working on the same tables/rows.

P.S. you should not write any new code using the ancient mysql_* functions. They are no longer maintained and community has begun process of deprecating them. Instead you should lean how to use PDO or MySQLi with prepared statements. If you decide to go with PDO, then here is a good tutorial.

Upvotes: 2

SSH This
SSH This

Reputation: 1929

No of course not, it will run sequentially, it won't move on until the function finishes and returns

Upvotes: 0

Related Questions