php 的 mysqli::commit 有一个 $name 参数 - 它有什么作用

php's mysqli::commit has a $name param - what does it do

https://www.php.net/manual/en/mysqli.commit.php

public mysqli::commit(int $flags = 0, ?string $name = null): bool

Parameters
flags: A bitmask of MYSQLI_TRANS_COR_* constants.
name: If provided then COMMIT/*name*/ is executed.

我的问题:什么是 COMMIT/*name*/ ??

我找不到关于此的任何 Mysql 文档

https://dev.mysql.com/doc/refman/8.0/en/commit.html
https://dev.mysql.com/doc/refman/8.0/en/innodb-autocommit-commit-rollback.html

也没有在野外使用

当您start a transaction, you have the option of creating a savepoint name进行交易时。然后您可以使用该名称进行提交。来自 MySQL 文档:

The SAVEPOINT statement sets a named transaction savepoint with a name of identifier. If the current transaction has a savepoint with the same name, the old savepoint is deleted and a new one is set.

所以我打开了查询日志记录

这就是记录的内容

将名称传递给 commit():

Query   START TRANSACTION
Query   INSERT INTO `bob` (`t`) VALUES ("test 1")
Query   SAVEPOINT `foo`
Query   INSERT INTO `bob` (`t`) VALUES ("test 2")
Query   COMMIT /*foo*/

两个查询都已记录

传递名称回滚:

Query   START TRANSACTION
Query   INSERT INTO `bob` (`t`) VALUES ("test 1")
Query   SAVEPOINT `foo`
Query   INSERT INTO `bob` (`t`) VALUES ("test 2")
Query   ROLLBACK /*foo*/
Query   COMMIT /*comment*/

两个插入都没有发生...整个事务被回滚

简而言之:

mysqli::commitmysqli::rollback 有 $name 参数,除了向查询添加评论外不做任何事情。

要真正回滚到保存点,您必须执行查询 (ROLLBACK TO `name`)。

mysqli 扩展提供了 savepoint($name) 方法,但没有 rollback_to_savepoint!