Opened 12 years ago
Closed 8 years ago
#22115 closed enhancement (wontfix)
Further Simplifying errors
Reported by: | msolution | Owned by: | johnbillion |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.4.2 |
Component: | Database | Keywords: | has-patch |
Focuses: | Cc: |
Description
tracking errors while making API's and cron jobs, is a tad difficult.
from the latest wordpress pack, /includes/wp-db.php
function query( $query ) { ... ... if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() ); // If there is an error then take note of it.. if ( $this->last_error = mysql_error( $this->dbh ) ) { $this->print_error(); return false; } ... ...
if we change the above to simply
// If there is an error then take note of it.. $this->last_error = ''; if ( $this->last_error = mysql_error( $this->dbh ) ) $this->print_error(); if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller(), $this->last_error ); // If there is an error then take note of it.. if ( ! empty( $this->last_error ) ) return false;
then we have all required info in the array queries, for use later. may it be wp_footer, or for a plugin as debug info.
Attachments (2)
Change History (11)
#6
@
11 years ago
We could take this a little further. My Query Monitor plugin extends the wpdb
class in order to log the result of each query (the number of affected rows) in the $wpdb->queries
array. When a result is an error it adds it as a WP_Error
. The code can be seen here.
#9
@
8 years ago
- Milestone Future Release deleted
- Resolution set to wontfix
- Status changed from reviewing to closed
I'm going to close this in favour of the functionality remaining in a debugging plugin (as mentioned above, Query Monitor provides this). I don't want to increase the amount of memory that wpdb
uses on every database call, even if it is a small increase.
A good amount of code has changed in WPDB since the original patch here. I've refreshed the patch, though note that I still leave the call to
print_error()
in the same place rather than moving it up. This is mostly since WPDB now automatically tries to reconnect to the DB if the connection is lost - something that didn't happen when this patch was originally submitted.I tested this briefly with bad queries and the Debug Bar plugin installed with
SAVEQUERIES
defined, and while Debug Bar doesn't use this extra value, I still wanted to make sure it didn't throw it off that it was there. It still works smoothly.So I think this is still a good patch.
Note that this will need to be refreshed again if/when #21663 is applied to account for MySQLi.