Function name: mysqli::release_savepoint()
Applicable version: PHP 5.5.0 and above
Function Description: This function is used to free the resource of a specified save point in a transaction so that it is no longer available.
Syntax: bool mysqli::release_savepoint(string $savepoint)
parameter:
Return value: Return true if the save point is successfully released, otherwise return false.
Sample code:
<?php // 创建数据库连接$mysqli = new mysqli("localhost", "username", "password", "database"); // 检查连接是否成功if ($mysqli->connect_errno) { echo "连接数据库失败:" . $mysqli->connect_error; exit(); } // 开始事务$mysqli->begin_transaction(); // 创建保存点$mysqli->savepoint("my_savepoint"); // 执行一些数据库操作// 释放保存点if ($mysqli->release_savepoint("my_savepoint")) { echo "保存点已成功释放"; } else { echo "释放保存点失败"; } // 提交事务$mysqli->commit(); // 关闭数据库连接$mysqli->close(); ?>
In the above example, we first create a database connection. Then we start a transaction using begin_transaction()
method and create a savepoint called "my_savepoint" using savepoint()
method. Next, we can perform some database operations. Finally, we use release_savepoint()
method to release the savepoint. If the release is successful, the output "Savepoint has been successfully released"; otherwise the output "Savepoint has failed to be released". Finally, we use the commit()
method to submit the transaction and close the database connection using the close()
method.