PHP/mysql获取UPDATE语句的受影响行数 [英] PHP/mysql get number of affected rows of UPDATE statement

查看:663
本文介绍了PHP/mysql获取UPDATE语句的受影响行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用php/mysql如何获取查询影响的行数?

With php/mysql how can i get the number of rows that a query affected?

到目前为止我尝试过的事情:

what i tried so far:

$result = mysql_query($q);
mysql_num_rows($result);

但是它说 警告:mysql_num_rows():提供的参数不是有效的MySQL结果资源

but it says that Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

推荐答案

(如果您使用的是 PDO (我会建议),对于直接查询 exec() 返回受影响的数量行.对于预备语句,有一种称为

if you're using PDO (wich i would recommend), for a direct query exec() returns the number of affected rows. for Prepared Statements theres a method called rowCount().

如果您使用的是 mysql功能,则有

if you're using the mysql-functions, there's mysql_affected_rows().


似乎您正在使用mysql函数.
mysql_num_rows ,这是您正在使用的,返回长度您的结果集(例如SELECT语句).您需要使用的是mysql_affected_rows(如前所述).


seems like you're using the mysql-functions. mysql_num_rows, wich is what you're using, returns the length of your result set (for SELECT-Statements for example). what you need to use is mysql_affected_rows (as already said).

这篇关于PHP/mysql获取UPDATE语句的受影响行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆