MySQLi - Begin Transaction

语法

public bool mysqli::begin_transaction ([ int $flags [, string $name ]] )

定义和用法

它用于启动事务。

示例

试试下面的例子 −

<?php
   $servername = "localhost:3306";
   $username = "root";
   $password = "";
   $dbname = "TUTORIALS";
   $conn = new mysqli($servername, $username, $password, $dbname);
   
   if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
   } 
   echo"Database connected 
";
   mysqli_begin_transaction($conn, MYSQLI_TRANS_START_READ_ONLY);

   mysqli_query($conn, "SELECT id, name FROM tutorials_auto LIMIT 1");
   mysqli_commit($conn);
   
   mysqli_close($conn);
?>

上述代码的示例输出应该是这样的 -

Database connected

mysqli_useful_functions.html