[英]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? 从理论上讲,第二行是否可以在第一行完成DELETE之前执行? If so, how do I make the code NOT asynchronous?
如果是这样,我如何使代码不异步? I need to ensure that the DELETE is completed before moving on.
我需要确保在继续之前完成DELETE。 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
这应该有所帮助: 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. PS你不应该使用古老的
mysql_*
函数编写任何新代码。 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 .
相反,你应该倾向于如何在准备好的语句中使用PDO或MySQLi 。 If you decide to go with PDO, then here is a good tutorial .
如果您决定使用PDO,那么这是一个很好的教程 。
当然不是,它会顺序运行,在函数完成并返回之前不会继续运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.