I am unsure whether this is WordPress specific or perhaps is more associated with mySQL. I'm attempting to discover an amount be came back when the transaction using the database fails. Within the following scenario, I'm upgrading a row. If no values are transformed false is came back. If changes are created true is came back. How do i know if the transaction has unsuccessful?
$result = $wpdb->update($this->table_name, $dbfields, $where); if($result == false)//do fail - this is not really a fail! if($result == true)//do success
Any pointers appreciated.
Have a look in
wp-includes\wp-db.php. The header comments of wpdb's update function states:
* @return int|false The number of rows updated, or false on error.
So, I'd suspect that you would like to obtain the distinction between
false (a boolean value showing failing) and
0 (an integer showing that no rows were came back.)
Should you compare using
0 are equal. You thus want to use the
=== operator to check on whether you are coping with the boolean
false or even the integer
So, try these:
if ($result === false) // Fail -- the "===" operator compares type as well as value if ($result === 0) // Success, but no rows were updated if ($result > 0) // Success, and updates were done. $result is the number of affected rows.
See the PHP manual for additional info on the === comparison operator.