Possible return values for mysql_affected_rows()

前端 未结 2 1195
我在风中等你
我在风中等你 2021-01-29 16:39

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

相关标签:
2条回答
  • 2021-01-29 17:25

    FROM Docs

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

    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.

    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.

    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.

    0 讨论(0)
  • 2021-01-29 17:40
    1. www.google.com
    2. mysql_affected_rows , search
    3. http://php.net/manual/en/function.mysql-affected-rows.php

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

    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.

    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.

    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.

    Important:

    don't use mysql_* as is deprecated

    0 讨论(0)
提交回复
热议问题