dousui4577 2010-09-11 20:44
浏览 25
已采纳

如何同时从多个脚本更新相同的mysql行?

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 any 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?

  • 写回答

1条回答 默认 最新

  • du20150401 2010-09-11 20:54
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记