Home > Backend Development > PHP Problem > How to use php mysqli_rollback function

How to use php mysqli_rollback function

藏色散人
Release: 2023-02-22 19:30:02
Original
3002 people have browsed it

php The mysqli_rollback function is used to roll back the current transaction of the specified database connection. Its syntax is mysqli_rollback(connection). The parameter connection is required and refers to the MySQL connection to be used.

How to use php mysqli_rollback function

php How to use the mysqli_rollback function?

Definition and usage

mysqli_rollback() function rolls back the current transaction of the specified database connection.

Tip: Please see the mysqli_commit() function, which is used to commit the current transaction for the specified database connection. Please see the mysqli_autocommit() function for turning automatic commit of database modifications on or off.

Syntax

mysqli_rollback(connection);
Copy after login

Parameters

connection Required. Specifies the MySQL connection to use.

Return value: TRUE if successful, FALSE if failed.

PHP Version: 5

Turn off autocommit, do some queries, submit the query, then roll back the current transaction:

<?php 
// 假定数据库用户名:root,密码:123456,数据库:RUNOOB 
$con=mysqli_connect("localhost","root","123456","RUNOOB"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "连接 MySQL 失败: " . mysqli_connect_error(); 
} 
// 关闭自动提交
mysqli_autocommit($con,FALSE);
// 插入数据
mysqli_query($con,"INSERT INTO websites (name, url, alexa, country)
VALUES (&#39;百度&#39;,&#39;https://www.baidu.com/&#39;,&#39;4&#39;,&#39;CN&#39;)");
mysqli_query($con,"INSERT INTO websites (name, url, alexa, country)
VALUES (Facebook&#39;,&#39;https://www.facebook.com/&#39;,&#39;2&#39;,&#39;USA&#39;)");
// 提交事务
mysqli_commit($con);
//回滚事务
mysqli_rollback($con);
// 关闭连接
mysqli_close($con);
?>
Copy after login

The above is the detailed content of How to use php mysqli_rollback function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template