简体   繁体   中英

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.

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.

PS 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 .

当然不是,它会顺序运行,在函数完成并返回之前不会继续运行

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM