0

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.

2
  • Other answers are correct. It's sequential. However you can (and usually should) check the response from mysql before continuing with the script. I'm guessing you're not doing this, otherwise the sequential issue would be moot. Commented Apr 18, 2012 at 22:29
  • Sounds like wrapping a transaction around the two would solve any problems with concurrent access. Commented Apr 19, 2012 at 21:29

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.