How to UPDATE the same mysql row from multiple scripts at the same time?
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.
精彩评论