当前位置: 动力学知识库 > 问答 > 编程问答 >

Is it ok to run whole PHP application in a MySQL transaction?

问题描述:

Is it ok to run whole PHP application in a MySQL transaction?

Is there any side effects?

I mean something like this:

  1. Client requests A.php
  2. A.php -> start mysql transaction
  3. A.php -> execute and process request
  4. A.php -> commit mysql transaction
  5. send requested data to client

网友答案:

I would not call this running the whole PHP application in one transaction, but rather a PHP script that treats each request in a separate transaction.

That is fine, as long as you are aware of transaction related concepts, such as locking, deadlocks, starvation, ... In essence, you should like in any other environment not lock database objects longer than necessary, prefer fine grained row locks over full table locks and protect your database against deadlocks.

But as those same concepts apply in a pure SQL engine based (stored procedure) solution, there is no particular reason not to do this in PHP.

分享给朋友:
您可能感兴趣的文章:
随机阅读: