[英]mysql_query(): how to check whether any rows are updated in case of UPDATE SQL
I am using mysql_query() to execute UPDATE SQL on my table. 我正在使用mysql_query()在表上执行UPDATE SQL。 I want to know whether the query has updated any row or not.
我想知道查询是否更新了任何行。
// $query contains UPDATE SQL
$result = mysql_query($query, $connection);
if(!$result) {
die("Database connection failed: " . mysql_error());
}
I tried to check value of $result, but it always comes out to be 1 for both cases(0 or more than 0 rows updated). 我试图检查$ result的值,但是在两种情况下,它总是得出1(更新0行或多于0行)。
Can anyone please help. 谁能帮忙。
Thanks. 谢谢。
Use mysql_affected_rows()
. 使用
mysql_affected_rows()
。 It returns the number of modified rows in the last query run. 它返回上一次查询运行中已修改的行数。
$numRows = mysql_affected_rows($connection).
尝试使用mysql_affected_rows()
。
为了完整起见,您也可以通过ROW_COUNT() function
在SQL中找到此答案,尽管mysql_affected_rows
对于此任务而言更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.