MySQLi - 影響行數



語法

mysqli_affected_rows(connection);

定義及用法

它用來獲取先前 MySQL 操作中受影響的行數的資訊。

示例

試用以下示例 −

<?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 \n";
   
   $sql = "SELECT * FROM Tutorials_auto";
   mysqli_query($conn,$sql); 
   echo "Affected rows: " . mysqli_affected_rows($conn);
   
   $conn->close();
?>

以上程式碼的示例輸出應如下 −

Database connected Affected rows: 2
mysqli_useful_functions.htm
廣告
© . All rights reserved.