如何知道更新了多少行mysql [英] How to know how many mysql lines updated
问题描述
我要更新很多数据库行,我想知道我已经更新了几行.
I'm going to update a lot of database lines and i want to know how many lines i've updated.
示例:如果我的数据库包含以下4行
Example : if i've database with the following 4 lines
INSERT INTO `drink` VALUES (1, 'Non-Alcoholic', 'tea');
INSERT INTO `drink` VALUES (2, 'Non-Alcoholic', 'tea');
INSERT INTO `drink` VALUES (3, 'Non-Alcoholic', 'coffee');
INSERT INTO `drink` VALUES (4, 'Non-Alcoholic', 'pepsi');
我将使用以下内容进行更新
and i'm going to make updates using the following
$sql= "update drink set cat='tea' WHERE cat= 'Non-Alcoholic' AND subcat = 'tea'";
很明显,它只会更新2行
it would be clear that it would update only 2 lines
INSERT INTO `drink` VALUES (1, 'tea', 'tea');
INSERT INTO `drink` VALUES (2, 'tea', 'tea');
INSERT INTO `drink` VALUES (3,'Non-Alcoholic', 'coffee');
INSERT INTO `drink` VALUES (4,'Non-Alcoholic', 'pepsi');
现在我的问题是我如何知道它已更新多少行,我希望将其显示为消息或其他内容,但我必须知道它.
Now my question how i know how many lines it have updated, i want it to be shown as message or whatever but i must know it.
所以任何想法或方法 谢谢你的帮助
so any idea or how to do it thank you for help
推荐答案
mysql_affected_rows
:获取先前的MySQL操作中受影响的行数:
mysql_affected_rows
: Get number of affected rows in previous MySQL operation :
...
$updated_count = mysql_affected_rows();
...
在查询后放入上面的语句以计算受影响的行.
Put above statement after your queries to count the affected rows.
这篇关于如何知道更新了多少行mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!