[wp-trac] [WordPress Trac] #33395: Pass $allow_bail to fallback attempt in $wpdb->db_connect

WordPress Trac noreply at wordpress.org
Mon Aug 17 22:42:49 UTC 2015


#33395: Pass $allow_bail to fallback attempt in $wpdb->db_connect
--------------------------+-----------------------------
 Reporter:  bobbywalters  |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Database      |    Version:  4.2.4
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When a database connection can not be established and a fallback call is
 attempted the value of $allow_bail is not passed to the second call of
 db_connect. This means the fallback attempt will always bail.

 This is the line of concern:
 https://core.trac.wordpress.org/browser/tags/4.2.4/src/wp-includes/wp-
 db.php#L1468

 Changing from:

 {{{
 if ( $attempt_fallback ) {
         $this->use_mysqli = false;
         $this->db_connect();
 }
 }}}


 to

 {{{
 if ( $attempt_fallback ) {
         $this->use_mysqli = false;
         $this->db_connect( $allow_bail );
 }
 }}}

 Will honor the $allow_bail value from the original call to be passed to
 the fallback attempt if it is necessary.

 A test scenario is:
 1. Verify the database is NOT running so all connection attempts fail.
 2. A sample script PHP script that would verify the $allow_bail flag is
 passed along to the fallback attempt:


 {{{
 <?php
 define('SHORTINIT', true);
 define('WP_DEBUG', true); // triggers $wpdb->show_errors()
 define('WP_SETUP_CONFIG', true); // prevents db_connect() call within new
 wpdb(...)

 require 'wp-config.php';

 global $wpdb;
 echo "Calling wpdb->db_connect( false )...\n";
 $wpdb->db_connect( false );
 echo "wpdb->bail() was not called because you can see me!\n";
 }}}

 A work around is possible by calling

 {{{
 $wpdb->hide_errors();
 }}}

 or ensuring WP_DEBUG is not true (calling hide_errors() is safer since you
 can't undefine a constant) prior to

 {{{
 $wpdb->db_connect();
 }}}

 but this goes further down the error handling path than it needs to.

 I can provide additional information if necessary. Thanks in advance for
 taking a look at this.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33395>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list