I’m not sure whether this question is WordPress specific or is more related to mySQL. I am trying to find out what would be returned if the transaction with the database fails.
In the following scenario, I am updating a row. If none of the values are changed false is returned. If changes are made true is returned. How can I tell if the transaction has failed?
$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.
Take a look in
wp-includeswp-db.php
. The header comments of wpdb’s update function says:So, I’d suspect that you want to find the difference between
false
(a boolean value indicating a failure) and0
(an integer indicating that no rows were returned.)If you compare using
==
,false
and0
are equal. You therefore need to use the===
operator to check whether you’re dealing with the booleanfalse
or the integer0
.So, try these:
See the PHP manual for more information on the === comparison operator.