Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 235 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$wpdb - what does it return on fail?

#1
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.

Reply

#2
Take a look in `wp-includes\wp-db.php`. The header comments of wpdb's update function says:

* @return int|false The number of rows updated, or false on error.

So, I'd suspect that you want to find the difference between `false` (a boolean value indicating a failure) and `0` (an integer indicating that no rows were returned.)

If you compare using `==`, `false` and `0` are equal. You therefore need to use the `===` operator to check whether you're dealing with the boolean `false` or the integer `0`.

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](

[To see links please register here]

) for more information on the === comparison operator.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through