mysql_affected_rows()的可能返回值 [英] Possible return values for mysql_affected_rows()

查看:148
本文介绍了mysql_affected_rows()的可能返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我php中函数 mysql_affected_rows() (同时更新)的所有可能返回值是什么?同样在什么情况下返回值?

Can anyone please tell me what are all the possible return values for the function mysql_affected_rows() (while update) in php? Also return values is for what circumstance?

如果更新查询没有更新任何内容或由于错误而停止,它将返回-1还是0?多数民众赞成在我的问题吗?

推荐答案

FROM 文档

成功返回受影响的行数,如果最后一次查询失败,则返回-1.

Returns the number of affected rows on success, and -1 if the last query failed.

如果最后一个查询是不带WHERE子句的DELETE查询,则将从表中删除所有记录,但是对于4.1.2之前的MySQL版本,此函数将返回零. 使用UPDATE时,MySQL将不会更新新值与旧值相同的列.这可能导致mysql_affected_rows()可能实际上不等于匹配的行数,而实际上不等于查询实际影响的行数.

If the last query was a DELETE query with no WHERE clause, all of the records will have been deleted from the table but this function will return zero with MySQL versions prior to 4.1.2. When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.

REPLACE语句首先删除具有相同主键的记录,然后插入新记录.此函数返回删除的记录数加上插入的记录数.

The REPLACE statement first deletes the record with the same primary key and then inserts the new record. This function returns the number of deleted records plus the number of inserted records.

对于"INSERT ... ON DUPLICATE KEY UPDATE"查询,如果执行插入操作,则返回值为1;对于现有行的更新,返回值为2.

In the case of "INSERT ... ON DUPLICATE KEY UPDATE" queries, the return value will be 1 if an insert was performed, or 2 for an update of an existing row.

这篇关于mysql_affected_rows()的可能返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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