[php-src] Issue #7818: Add mysqli_rollback_to
| From: | KapitanOczywisty | Date: | Thu, 23 Dec 2021 12:32:53 +0000 |
| Subject: | [php-src] Issue #7818: Add mysqli_rollback_to | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-238543@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7818
Author: KapitanOczywisty
### Description
In PHP 5.5
mysqli::savepoint and mysqli::release_savepoint were added, but
not rollback_to. Maybe there is some database engine where savepoints have multiple
purposes, but in mariadb the only use of savepoints is to call query ROLLBACK TO
name query manually.
For completion: existing rollback with $name is doing nothing (only adding comment) at
least in mariadb/mysql.
Method signature
```php
class mysqli { /* ... */
public function rollback_to(string $name) : bool;
}
```
Sample test sequence
```php
mysqli_query($link, 'DROP TABLE IF EXISTS test');
mysqli_query($link, 'CREATE TABLE test(id INT) ENGINE = InnoDB');
mysqli_begin_transaction($link);
mysqli_query($link, 'INSERT INTO test(id) VALUES (1)');
mysqli_savepoint($link, 'foo');
mysqli_query($link, 'INSERT INTO test(id) VALUES (2)');
mysqli_rollback_to($link, 'foo');
mysqli_commit($link);
$res = mysqli_query($link, "SELECT * FROM test");
var_dump($res->num_rows); // int(1)
```