如何在PHP中获取受MySQL查询影响的行?

时间:2017-11-30 05:27:00

标签: php mysql mysqli sql-update rows

从PHP开始,如果我使用status执行如下查询:

mysqli_stmt_execute

如何确定表中哪些行实际更新并受查询影响?

请注意,我希望仅在PHP中解决此问题,而不使用数据库触发器等。非常具体地说,这个问题是因为我们试图从数据库中删除所有触发器。

2 个答案:

答案 0 :(得分:1)

$string="UPDATE users SET hair_color = 'brown' WHERE height > 180";
//Update Query String which will perform in update query

$update_query=mysqli_query($connection,$string);
//by this we are actually running our update queries.    

$total_affected_rows=mysqli_affected_rows($con); 
//By this line you will get total affected rows

//if you need to select and show all the affected rows then you can make a 
//query

$sql=mysqli_query($con,"SELECT * FROM users WHERE height > 180");

答案 1 :(得分:1)

您可以使用mysqli_stmt_affected_rows()来获取受影响的行

点击http://php.net/manual/en/mysqli-stmt.affected-rows.php