Comparison of php mysqli_commit() function and mysqli_autocommit() function

巴扎黑
Release: 2023-03-07 21:22:01
Original
2000 people have browsed it

In this article, we introduce the definition, syntax and usage of the mysqli_commit and mysqli_autocommit functions to compare the differences between them. First, let’s introduce the mysqli_commit function:

Definition and usage

mysqli_commit() The function commits the current transaction of the specified database connection.

Tip: 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);
Copy after login

Parameter description

connection Required. Specifies the MySQL connection to use.

Return value:

Returns TRUE if successful, returns FALSE if failed.

Definition and usage

mysqli_autocommit() The function turns on or off automatic submission of database modifications.

Syntax

mysqli_autocommit(connection,mode);
Copy after login

Parameter description

connection Required. Specifies the MySQL connection to use. ​

mode ​ ​ Required. If set to FALSE, auto-commit is turned off. If set to TRUE, auto-commit is turned on (committing any pending queries).

Return value:

Returns TRUE if successful, returns FALSE if failed.

Example display:

Turn off automatic submission, do some queries, and 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 (&#39;百度&#39;,&#39;https://www.baidu.com/&#39;,&#39;4&#39;,&#39;CN&#39;)");  
// 提交事务  
mysqli_commit($con);  
// 关闭连接  
mysqli_close($con);  
?>
Copy after login

The above is the detailed content of Comparison of php mysqli_commit() function and mysqli_autocommit() function. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!