Home > Article > Backend Development > How to use php mysqli_commit function
php The mysqli_commit function is used to submit the current transaction of the specified database connection. Its syntax is mysqli_commit(connection). The parameter connection is required and refers to the MySQL connection to be used.
php How to use the mysqli_commit function?
Definition and usage
mysqli_commit() function commits the current transaction for the specified database connection.
Tips:
Please check the mysqli_autocommit() function, which is used to turn on or off automatic submission of database modifications. Please see the mysqli_rollback() function for rolling back the current transaction.
Syntax
mysqli_commit(connection);
Parameters
connection Required. Specifies the MySQL connection to use.
Return value: TRUE if successful, FALSE if failed.
PHP Version: 5
Example
Turn off auto-submit, do some queries, then submit the query:
<?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 ('百度','https://www.baidu.com/','4','CN')"); // 提交事务 mysqli_commit($con); // 关闭连接 mysqli_close($con); ?>
The above is the detailed content of How to use php mysqli_commit function. For more information, please follow other related articles on the PHP Chinese website!