I am executing SQL (MySQL) commands from PHP. There are several possible outcomes to each execution:
- Record updated to new value
- Record updated, but values happen to be the same
- Record finds no rows to update (ie, no rows match the
WHERE
clause)
I am wondering how to differentiate between #'s 1 and 3: both cases return zero as the number of rows being affected, so:
$result = $db->exec($statement)
will have $result == 0
in both cases. How can I tell the difference?
EDIT: I meant to ask how to differentiate between scenarios TWO and 3, not 1 and 3! Sorry for the inconvenience...
rowCount()
. MySQLi?affected_rows()
– Howardhowarthmysql_*
functions are deprecated @Nasia and will never receive a recommendation from me. The code the OP has posted indicates they may be using something other than the old MySQL API. Read carefully, the OP states using MySQL (the database) notmysql_*
the API. ¯\_(ツ)_/¯ – Howardhowarth