action

优质
小牛编辑
136浏览
2023-12-01

Action(事务)

启动一个事务

action( $callback )
  • $callback [function]

    事务内执行的方法.

Return: void不是每个数据库引擎都支持事务。你必须在使用前检查。如果返回false,则回滚事务。
$database->action(function($database) {    $database->insert("account", [        "name" => "foo",        "email" => "bar@abc.com"    ]);    $database->delete("account", [        "user_id" => 2312    ]);    // If you want to  find something wrong, just return false to rollback the whole transaction.    if ($database->has("post", ["user_id" => 2312]))    {        return false;    }});