I am developing a wordpress site and I would like to be able to log and handle mysql errors from wordpress core.
My site has a mix of wordpress pages and posts + a few php pages that run under the wordpress engine. I configured the php.ini to prepend a php file to all php scripts with the error handling functions. They are working fine to catch php errors both in the wordpress core and in my own php scripts.
I also catch all the MySQL errors in my own php scripts. For example, failure to connect to a database, etc.
I would like to be able to also catch, log and process eventual MySQL errors from the wordpress core application.
Any suggestions?
Thanks.
I was reading through the codex and I couldn’t find an answer
You should be using the
wpdb
class for all your own queries. All core queries also usewpdb
. Seewpdb
Show and Hide SQL ErrorsAlso see SAVEQUERIES constant for
wp-config.php
:usage example:
There are also a number of helpful debugging plugins, like Debug Bar & Console. Search the WordPress plugin repository for this and other debugging related plugins.
One way to do this:
db.php
inwp-content
. WordPress will read this file immediately before instantiating the$wpdb
object.class
which extendswpdb
, and overwrite theprint_errors
method to do whatever you want.$wpdb
(eg.,$wpdb = new wpdb2(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
)$wpdb
instead.try with
as i am working with ajax, this is directly in string form.