?php
// 假定数据库用户名:root,密码:123456,数据库:codingdict
$con=mysqli_connect("localhost","root","123456","codingdict");
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_query($con,"INSERT INTO websites (name, url, alexa, country)
VALUES (Facebook','https://www.facebook.com/','2','USA')");
// 提交事务
mysqli_commit($con);
//回滚事务
mysqli_rollback($con);
// 关闭连接
mysqli_close($con);
?>