您好我正在尝试使用mysqli_affected_rows函数,但它总是返回0可以有人帮忙。试图通过MSQLI OOP完成它。
<?php
$servername ="localhost";
$username ="root";
$password ="testdb";
$database ="mydb";
$conn = new mysqli($servername, $username, $password, $database);
if($conn->connect_error)
{
die ("The Database connection is not established : " .connect_error);
}
echo "connection established";
//editing record
$sql_update = "update mytbl SET fname='Nitin Sharma' where sr=2";
echo "The affected Rows :" .mysqli_affected_rows($conn);
$conn->close();
?>
表值:
答案 0 :(得分:0)
您错过了执行SQL查询。
$conn->query($sql_update);
答案 1 :(得分:-1)
您需要先mysqli_query
$sql_update = "update mytbl SET fname='Nitin Sharma' where sr=2";
$conn->mysqli_query($sql_update);
echo "The affected Rows :" .$conn->affected_rows;