关闭自动提交,做一些查询,然后提交查询:
<?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); ?>