Home > php教程 > php手册 > body text

PHP mysqli_autocommit() function

WBOY
Release: 2016-09-23 03:30:09
Original
1782 people have browsed it

Definition and Usage

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

Tips: Please take a look at the mysqli_commit() function, which is used to commit the current transaction of the specified database connection. Please see the mysqli_rollback() function for rolling back the current transaction.


Grammar

mysqli_autocommit(connection,mode);

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).

Technical details

Return value: Returns TRUE if successful and FALSE if failed.
PHP version: 5+

Examples

Turn off auto-submit, do some queries, then submit the query:

<?<span style="color: #000000;">php 
</span><span style="color: #008000;">//</span><span style="color: #008000;"> 假定数据库用户名:root,密码:123456,数据库:RUNOOB </span>
<span style="color: #800080;">$con</span>=<span style="color: #008080;">mysqli_connect</span>("localhost","root","123456","RUNOOB"<span style="color: #000000;">); 
</span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">mysqli_connect_errno</span>(<span style="color: #800080;">$con</span><span style="color: #000000;">)) 
{ 
    </span><span style="color: #0000ff;">echo</span> "连接 MySQL 失败: " . <span style="color: #008080;">mysqli_connect_error</span><span style="color: #000000;">(); 
} 

</span><span style="color: #008000;">//</span><span style="color: #008000;"> 关闭自动提交</span>
<span style="color: #008080;">mysqli_autocommit</span>(<span style="color: #800080;">$con</span>,<span style="color: #0000ff;">FALSE</span><span style="color: #000000;">);

</span><span style="color: #008000;">//</span><span style="color: #008000;"> 插入一些值</span>
<span style="color: #008080;">mysqli_query</span>(<span style="color: #800080;">$con</span>,"<span style="color: #000000;">INSERT INTO websites (name, url, alexa, country)
VALUES ('百度','https://www.baidu.com/','4','CN')</span>"<span style="color: #000000;">);

</span><span style="color: #008000;">//</span><span style="color: #008000;"> 提交事务</span>
<span style="color: #008080;">mysqli_commit</span>(<span style="color: #800080;">$con</span><span style="color: #000000;">);

</span><span style="color: #008000;">//</span><span style="color: #008000;"> 关闭连接</span>
<span style="color: #008080;">mysqli_close</span>(<span style="color: #800080;">$con</span><span style="color: #000000;">);
</span>?>
Copy after login

Original address: http://www.manongjc.com/article/1204.html

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template