[wp-trac] [WordPress Trac] #64523: _do_query needs exception processing in class-wpdb.php

WordPress Trac noreply at wordpress.org
Fri Jan 16 21:57:48 UTC 2026


#64523: _do_query needs exception processing in class-wpdb.php
--------------------------+------------------------------
 Reporter:  randem06      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  6.9
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by randem06):

 Replying to [ticket:64523 randem06]:
 > When some plugins are loaded with error handling other plugins create
 exceptions with ex. "DESCRIBE" statements for tables that do not exist and
 an exception occurs, but does not when plugin is not loaded. Happens with
 Litespeed or most cache plugins and BotBanish.
 >
 > **Original Code**
 >
 > {{{#!php
 > <?php
 >
 >
 >       private function _do_query( $query ) {
 >               if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
 >                       $this->timer_start();
 >               }
 >
 >               if ( ! empty( $this->dbh ) ) {
 >                       $this->result = mysqli_query( $this->dbh, $query
 );
 >               }
 >
 >               ++$this->num_queries;
 >
 >               if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
 >                       $this->log_query(
 >                               $query,
 >                               $this->timer_stop(),
 >                               $this->get_caller(),
 >                               $this->time_start,
 >                               array()
 >                       );
 >               }
 >       }
 > }}}
 >
 >
 > **Should be something like**
 >
 > {{{#!php
 > <?php
 >
 >
 >       private function _do_query( $query ) {
 >               if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
 >                       $this->timer_start();
 >               }
 >
 > **            if ( ! empty( $this->dbh ) ) {
 >
 >                    try {
 >                       $this->result = mysqli_query( $this->dbh, $query
 );
 >
 >                    } catch (Exception $f) {
 >
 >                      // process exception here...
 >                    }
 >
 >               }**
 >
 >               ++$this->num_queries;
 >
 >               if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
 >                       $this->log_query(
 >                               $query,
 >                               $this->timer_stop(),
 >                               $this->get_caller(),
 >                               $this->time_start,
 >                               array()
 >                       );
 >               }
 >       }
 > }}}


 I used the following code to fix the issue.

 {{{#!php
 <?php



                 if ( ! empty( $this->dbh ) ) {

                         try {

                                 $this->result = mysqli_query( $this->dbh,
 $query );

                         } catch (exception $f) {

                                 $this->result = $f;
                         }
                 }6
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64523#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list