开发者

How to UPDATE the same mysql row from multiple scripts at the same time?

开发者 https://www.devze.com 2023-01-15 14:01 出处:网络
I am forking some php scripts and I need to update a mysql row to track some progress. I read that I should use InnoDB for this but I coulnd\'t find a开发者_如何学Gony complete example I can understan

I am forking some php scripts and I need to update a mysql row to track some progress. I read that I should use InnoDB for this but I coulnd't find a开发者_如何学Gony complete example I can understand. A friend told me he uses this php code:

mysql_query("SET AUTOCOMMIT=0;");
mysql_query("START TRANSACTION;");
mysql_query("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;");

// UPDATE QUERY HERE

mysql_query("COMMIT;");
mysql_query("UNLOCK TABLES;");      
mysql_query("SET AUTOCOMMIT=1;");

He told me he tried other methods but everything else than that code overloaded his server after some time.

Does someone could tell me if this code will do what I need or if there's a better way to do it?


The database type doesn't matter. MySQL is designed to automatically queue the asynchronous requests and execute them in the order in which they arrive. However, the requests will probably not even be asynchronous, unless you have a lot of them running at once. Either way, you shouldn't have a problem with this, unless your scripts have to update the row in a specific order. In that case, you should use a single script where you can more closely control the updating order.

0

精彩评论

暂无评论...
验证码 换一张
取 消