Make WordPress Core


Ignore:
Timestamp:
02/02/2014 10:06:42 PM (10 years ago)
Author:
nacin
Message:

When the MySQL server has "gone away," attempt to reconnect and retry the query.

props pento.
see #5932.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/db.php

    r27073 r27075  
    3939        $this->_queries[] = $sql;
    4040        return $sql;
     41    }
     42
     43    /**
     44     * Test that WPDB will reconnect when the DB link dies
     45     * @ticket 5932
     46     */
     47    public function test_db_reconnect() {
     48        global $wpdb;
     49
     50        $var = $wpdb->get_var( "SELECT ID FROM $wpdb->users LIMIT 1" );
     51        $this->assertGreaterThan( 0, $var );
     52
     53        mysql_close( $wpdb->dbh );
     54        unset( $wpdb->dbh );
     55
     56        $var = $wpdb->get_var( "SELECT ID FROM $wpdb->users LIMIT 1" );
     57        $this->assertGreaterThan( 0, $var );
    4158    }
    4259
Note: See TracChangeset for help on using the changeset viewer.