简体   繁体   English

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

[英]How do I get the rows affected by a MySQL query in PHP?

From PHP, if I execute a query like the following with mysqli_stmt_execute : 从PHP,如果我使用mysqli_stmt_execute执行以下查询:

UPDATE users 
SET hair_color = 'brown' 
WHERE height > 180;

How can I figure out which rows in the table were actually updated and affected by the query? 如何确定表中的哪些行实际上已更新并受到查询的影响?

Please note that I am looking to solve this problem in only PHP, without the use of DB triggers, etc. Very specifically, this question came about because we're trying to remove all triggers from our DB. 请注意,我希望仅在PHP中解决此问题,而不使用DB触发器等。特别是,出现此问题是因为我们正试图从数据库中删除所有触发器。

$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");

you can use mysqli_stmt_affected_rows() to get the affected rows 您可以使用mysqli_stmt_affected_rows()获取受影响的行

check here http://php.net/manual/en/mysqli-stmt.affected-rows.php 在这里检查http://php.net/manual/en/mysqli-stmt.affected-rows.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM