Make WordPress Core


Ignore:
Timestamp:
02/02/2016 12:12:28 AM (11 years ago)
Author:
pento
Message:

WPDB: Add a close() method to wpdb, for when the connection needs to be manually closed.

In the event that it was closed prematurely, wpdb::query() will re-open the connection automatically.

Fixes #34903.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/wp-db.php

    r36385 r36433  
    30943094        }
    30953095
     3096
     3097        /**
     3098         * Closes the current database connection.
     3099         *
     3100         * @since 4.5.0
     3101         *
     3102         * @return bool True if the connection was succesfully closed, false if it wasn't, or the connection doesn't exist.
     3103         */
     3104        public function close() {
     3105                if ( ! $this->dbh ) {
     3106                        return false;
     3107                }
     3108
     3109                if ( $this->use_mysqli ) {
     3110                        $closed = mysqli_close( $this->dbh );
     3111                } else {
     3112                        $closed = mysql_close( $this->dbh );
     3113                }
     3114
     3115                if ( $closed ) {
     3116                        $this->dbh = null;
     3117                }
     3118
     3119                return $closed;
     3120        }
     3121
    30963122        /**
    30973123         * Whether MySQL database is at least the required minimum version.
Note: See TracChangeset for help on using the changeset viewer.