Php/docs/mysqli.commit
mysqli::commit
mysqli_commit
(PHP 5, PHP 7)
mysqli::commit -- mysqli_commit — 提交一个事务
返回值
成功时返回 true
, 或者在失败时返回 false
。
范例
Example #1 mysqli::commit() example
面向对象风格
<?php$mysqli = new mysqli("localhost", "my_user", "my_password", "world");/* check connection */if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit();}$mysqli->query("CREATE TABLE Language LIKE CountryLanguage");/* set autocommit to off */$mysqli->autocommit(FALSE);/* Insert some values */$mysqli->query("INSERT INTO Language VALUES ('DEU', 'Bavarian', 'F', 11.2)");$mysqli->query("INSERT INTO Language VALUES ('DEU', 'Swabian', 'F', 9.4)");/* commit transaction */$mysqli->commit();/* drop table */$mysqli->query("DROP TABLE Language");/* close connection */$mysqli->close();?>
过程化风格
<?php$link = mysqli_connect("localhost", "my_user", "my_password", "test");/* check connection */if (!$link) { printf("Connect failed: %s\n", mysqli_connect_error()); exit();}/* set autocommit to off */mysqli_autocommit($link, FALSE);mysqli_query($link, "CREATE TABLE Language LIKE CountryLanguage");/* Insert some values */mysqli_query($link, "INSERT INTO Language VALUES ('DEU', 'Bavarian', 'F', 11.2)");mysqli_query($link, "INSERT INTO Language VALUES ('DEU', 'Swabian', 'F', 9.4)");/* commit transaction */mysqli_commit($link);/* close connection */mysqli_close($link);?>