]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/wp-db.php
WordPress 4.5.1
[autoinstalls/wordpress.git] / wp-includes / wp-db.php
index 9ce6519be1f15b370c78a43c611a29fae167d7f6..066e851fa3e45270fe0a46908be12246a882fc49 100644 (file)
@@ -266,7 +266,7 @@ class wpdb {
         * @var array
         */
        var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta',
-               'terms', 'term_taxonomy', 'term_relationships', 'commentmeta' );
+               'terms', 'term_taxonomy', 'term_relationships', 'termmeta', 'commentmeta' );
 
        /**
         * List of deprecated WordPress tables
@@ -382,9 +382,18 @@ class wpdb {
         */
        public $term_taxonomy;
 
-       /*
-        * Global and Multisite tables
+       /**
+        * WordPress Term Meta table.
+        *
+        * @since 4.4.0
+        * @access public
+        * @var string
         */
+       public $termmeta;
+
+       //
+       // Global and Multisite tables
+       //
 
        /**
         * WordPress User Metadata table
@@ -840,7 +849,7 @@ class wpdb {
                 */
                $incompatible_modes = (array) apply_filters( 'incompatible_sql_modes', $this->incompatible_modes );
 
-               foreach( $modes as $i => $mode ) {
+               foreach ( $modes as $i => $mode ) {
                        if ( in_array( $mode, $incompatible_modes ) ) {
                                unset( $modes[ $i ] );
                        }
@@ -1035,22 +1044,48 @@ class wpdb {
                        $dbh = $this->dbh;
 
                if ( $this->use_mysqli ) {
-                       $success = @mysqli_select_db( $dbh, $db );
+                       $success = mysqli_select_db( $dbh, $db );
                } else {
-                       $success = @mysql_select_db( $db, $dbh );
+                       $success = mysql_select_db( $db, $dbh );
                }
                if ( ! $success ) {
                        $this->ready = false;
                        if ( ! did_action( 'template_redirect' ) ) {
                                wp_load_translations_early();
-                               $this->bail( sprintf( __( '<h1>Can&#8217;t select database</h1>
-<p>We were able to connect to the database server (which means your username and password is okay) but not able to select the <code>%1$s</code> database.</p>
-<ul>
-<li>Are you sure it exists?</li>
-<li>Does the user <code>%2$s</code> have permission to use the <code>%1$s</code> database?</li>
-<li>On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?</li>
-</ul>
-<p>If you don\'t know how to set up a database you should <strong>contact your host</strong>. If all else fails you may find help at the <a href="https://wordpress.org/support/">WordPress Support Forums</a>.</p>' ), htmlspecialchars( $db, ENT_QUOTES ), htmlspecialchars( $this->dbuser, ENT_QUOTES ) ), 'db_select_fail' );
+
+                               $message = '<h1>' . __( 'Can&#8217;t select database' ) . "</h1>\n";
+
+                               $message .= '<p>' . sprintf(
+                                       /* translators: %s: database name */
+                                       __( 'We were able to connect to the database server (which means your username and password is okay) but not able to select the %s database.' ),
+                                       '<code>' . htmlspecialchars( $db, ENT_QUOTES ) . '</code>'
+                               ) . "</p>\n";
+
+                               $message .= "<ul>\n";
+                               $message .= '<li>' . __( 'Are you sure it exists?' ) . "</li>\n";
+
+                               $message .= '<li>' . sprintf(
+                                       /* translators: 1: database user, 2: database name */
+                                       __( 'Does the user %1$s have permission to use the %2$s database?' ),
+                                       '<code>' . htmlspecialchars( $this->dbuser, ENT_QUOTES )  . '</code>',
+                                       '<code>' . htmlspecialchars( $db, ENT_QUOTES ) . '</code>'
+                               ) . "</li>\n";
+
+                               $message .= '<li>' . sprintf(
+                                       /* translators: %s: database name */
+                                       __( 'On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?' ),
+                                       htmlspecialchars( $db, ENT_QUOTES )
+                               ). "</li>\n";
+
+                               $message .= "</ul>\n";
+
+                               $message .= '<p>' . sprintf(
+                                       /* translators: %s: support forums URL */
+                                       __( 'If you don&#8217;t know how to set up a database you should <strong>contact your host</strong>. If all else fails you may find help at the <a href="%s">WordPress Support Forums</a>.' ),
+                                       __( 'https://wordpress.org/support/' )
+                               ) . "</p>\n";
+
+                               $this->bail( $message, 'db_select_fail' );
                        }
                }
        }
@@ -1061,7 +1096,7 @@ class wpdb {
         * Use esc_sql() or wpdb::prepare() instead.
         *
         * @since 2.8.0
-        * @deprecated 3.6.0
+        * @deprecated 3.6.0 Use wpdb::prepare()
         * @see wpdb::prepare
         * @see esc_sql()
         * @access private
@@ -1097,6 +1132,7 @@ class wpdb {
 
                $class = get_class( $this );
                if ( function_exists( '__' ) ) {
+                       /* translators: %s: database access abstraction class, usually wpdb or a class extending wpdb */
                        _doing_it_wrong( $class, sprintf( __( '%s must set a database connection for use with escaping.' ), $class ), E_USER_NOTICE );
                } else {
                        _doing_it_wrong( $class, sprintf( '%s must set a database connection for use with escaping.', $class ), E_USER_NOTICE );
@@ -1135,7 +1171,7 @@ class wpdb {
         * Use esc_sql() or wpdb::prepare() instead.
         *
         * @since 0.71
-        * @deprecated 3.6.0
+        * @deprecated 3.6.0 Use wpdb::prepare()
         * @see wpdb::prepare()
         * @see esc_sql()
         *
@@ -1235,13 +1271,15 @@ class wpdb {
         * Use this only before wpdb::prepare() or esc_sql().  Reversing the order is very bad for security.
         *
         * Example Prepared Statement:
-        *  $wild = '%';
-        *  $find = 'only 43% of planets';
-        *  $like = $wild . $wpdb->esc_like( $find ) . $wild;
-        *  $sql  = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE %s", $like );
+        *
+        *     $wild = '%';
+        *     $find = 'only 43% of planets';
+        *     $like = $wild . $wpdb->esc_like( $find ) . $wild;
+        *     $sql  = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE '%s'", $like );
         *
         * Example Escape Chain:
-        *  $sql  = esc_sql( $wpdb->esc_like( $input ) );
+        *
+        *     $sql  = esc_sql( $wpdb->esc_like( $input ) );
         *
         * @since 4.0.0
         * @access public
@@ -1474,7 +1512,7 @@ class wpdb {
 
                                if ( $attempt_fallback ) {
                                        $this->use_mysqli = false;
-                                       $this->db_connect();
+                                       return $this->db_connect( $allow_bail );
                                }
                        }
                } else {
@@ -1494,16 +1532,28 @@ class wpdb {
                                die();
                        }
 
-                       $this->bail( sprintf( __( "
-<h1>Error establishing a database connection</h1>
-<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>%s</code>. This could mean your host's database server is down.</p>
-<ul>
-       <li>Are you sure you have the correct username and password?</li>
-       <li>Are you sure that you have typed the correct hostname?</li>
-       <li>Are you sure that the database server is running?</li>
-</ul>
-<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='https://wordpress.org/support/'>WordPress Support Forums</a>.</p>
-" ), htmlspecialchars( $this->dbhost, ENT_QUOTES ) ), 'db_connect_fail' );
+                       $message = '<h1>' . __( 'Error establishing a database connection' ) . "</h1>\n";
+
+                       $message .= '<p>' . sprintf(
+                               /* translators: 1: wp-config.php. 2: database host */
+                               __( 'This either means that the username and password information in your %1$s file is incorrect or we can&#8217;t contact the database server at %2$s. This could mean your host&#8217;s database server is down.' ),
+                               '<code>wp-config.php</code>',
+                               '<code>' . htmlspecialchars( $this->dbhost, ENT_QUOTES ) . '</code>'
+                       ) . "</p>\n";
+
+                       $message .= "<ul>\n";
+                       $message .= '<li>' . __( 'Are you sure you have the correct username and password?' ) . "</li>\n";
+                       $message .= '<li>' . __( 'Are you sure that you have typed the correct hostname?' ) . "</li>\n";
+                       $message .= '<li>' . __( 'Are you sure that the database server is running?' ) . "</li>\n";
+                       $message .= "</ul>\n";
+
+                       $message .= '<p>' . sprintf(
+                               /* translators: %s: support forums URL */
+                               __( 'If you&#8217;re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ),
+                               __( 'https://wordpress.org/support/' )
+                       ) . "</p>\n";
+
+                       $this->bail( $message, 'db_connect_fail' );
 
                        return false;
                } elseif ( $this->dbh ) {
@@ -1541,11 +1591,11 @@ class wpdb {
         */
        public function check_connection( $allow_bail = true ) {
                if ( $this->use_mysqli ) {
-                       if ( @mysqli_ping( $this->dbh ) ) {
+                       if ( ! empty( $this->dbh ) && mysqli_ping( $this->dbh ) ) {
                                return true;
                        }
                } else {
-                       if ( @mysql_ping( $this->dbh ) ) {
+                       if ( ! empty( $this->dbh ) && mysql_ping( $this->dbh ) ) {
                                return true;
                        }
                }
@@ -1586,16 +1636,29 @@ class wpdb {
                        return false;
                }
 
+               wp_load_translations_early();
+
+               $message = '<h1>' . __( 'Error reconnecting to the database' ) . "</h1>\n";
+
+               $message .= '<p>' . sprintf(
+                       /* translators: %s: database host */
+                       __( 'This means that we lost contact with the database server at %s. This could mean your host&#8217;s database server is down.' ),
+                       '<code>' . htmlspecialchars( $this->dbhost, ENT_QUOTES ) . '</code>'
+               ) . "</p>\n";
+
+               $message .= "<ul>\n";
+               $message .= '<li>' . __( 'Are you sure that the database server is running?' ) . "</li>\n";
+               $message .= '<li>' . __( 'Are you sure that the database server is not under particularly heavy load?' ) . "</li>\n";
+               $message .= "</ul>\n";
+
+               $message .= '<p>' . sprintf(
+                       /* translators: %s: support forums URL */
+                       __( 'If you&#8217;re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ),
+                       __( 'https://wordpress.org/support/' )
+               ) . "</p>\n";
+
                // We weren't able to reconnect, so we better bail.
-               $this->bail( sprintf( ( "
-<h1>Error reconnecting to the database</h1>
-<p>This means that we lost contact with the database server at <code>%s</code>. This could mean your host's database server is down.</p>
-<ul>
-       <li>Are you sure that the database server is running?</li>
-       <li>Are you sure that the database server is not under particularly heavy load?</li>
-</ul>
-<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='https://wordpress.org/support/'>WordPress Support Forums</a>.</p>
-" ), htmlspecialchars( $this->dbhost, ENT_QUOTES ) ), 'db_connect_fail' );
+               $this->bail( $message, 'db_connect_fail' );
 
                // Call dead_db() if bail didn't die, because this database is no more. It has ceased to be (at least temporarily).
                dead_db();
@@ -1709,12 +1772,12 @@ class wpdb {
                } else {
                        $num_rows = 0;
                        if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
-                               while ( $row = @mysqli_fetch_object( $this->result ) ) {
+                               while ( $row = mysqli_fetch_object( $this->result ) ) {
                                        $this->last_result[$num_rows] = $row;
                                        $num_rows++;
                                }
                        } elseif ( is_resource( $this->result ) ) {
-                               while ( $row = @mysql_fetch_object( $this->result ) ) {
+                               while ( $row = mysql_fetch_object( $this->result ) ) {
                                        $this->last_result[$num_rows] = $row;
                                        $num_rows++;
                                }
@@ -1744,10 +1807,10 @@ class wpdb {
                        $this->timer_start();
                }
 
-               if ( $this->use_mysqli ) {
-                       $this->result = @mysqli_query( $this->dbh, $query );
-               } else {
-                       $this->result = @mysql_query( $query, $this->dbh );
+               if ( ! empty( $this->dbh ) && $this->use_mysqli ) {
+                       $this->result = mysqli_query( $this->dbh, $query );
+               } elseif ( ! empty( $this->dbh ) ) {
+                       $this->result = mysql_query( $query, $this->dbh );
                }
                $this->num_queries++;
 
@@ -1770,6 +1833,7 @@ class wpdb {
         * @param string       $table  Table name
         * @param array        $data   Data to insert (in column => value pairs).
         *                             Both $data columns and $data values should be "raw" (neither should be SQL escaped).
+        *                             Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.
         * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data.
         *                             If string, that format will be used for all of the values in $data.
         *                             A format is one of '%d', '%f', '%s' (integer, float, string).
@@ -1794,6 +1858,7 @@ class wpdb {
         * @param string       $table  Table name
         * @param array        $data   Data to insert (in column => value pairs).
         *                             Both $data columns and $data values should be "raw" (neither should be SQL escaped).
+        *                             Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.
         * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data.
         *                             If string, that format will be used for all of the values in $data.
         *                             A format is one of '%d', '%f', '%s' (integer, float, string).
@@ -1818,6 +1883,7 @@ class wpdb {
         * @param string       $table  Table name
         * @param array        $data   Data to insert (in column => value pairs).
         *                             Both $data columns and $data values should be "raw" (neither should be SQL escaped).
+        *                             Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.
         * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data.
         *                             If string, that format will be used for all of the values in $data.
         *                             A format is one of '%d', '%f', '%s' (integer, float, string).
@@ -1839,6 +1905,11 @@ class wpdb {
 
                $formats = $values = array();
                foreach ( $data as $value ) {
+                       if ( is_null( $value['value'] ) ) {
+                               $formats[] = 'NULL';
+                               continue;
+                       }
+
                        $formats[] = $value['format'];
                        $values[]  = $value['value'];
                }
@@ -1866,9 +1937,12 @@ class wpdb {
         * @param string       $table        Table name
         * @param array        $data         Data to update (in column => value pairs).
         *                                   Both $data columns and $data values should be "raw" (neither should be SQL escaped).
+        *                                   Sending a null value will cause the column to be set to NULL - the corresponding
+        *                                   format is ignored in this case.
         * @param array        $where        A named array of WHERE clauses (in column => value pairs).
         *                                   Multiple clauses will be joined with ANDs.
         *                                   Both $where columns and $where values should be "raw".
+        *                                   Sending a null value will create an IS NULL comparison - the corresponding format will be ignored in this case.
         * @param array|string $format       Optional. An array of formats to be mapped to each of the values in $data.
         *                                   If string, that format will be used for all of the values in $data.
         *                                   A format is one of '%d', '%f', '%s' (integer, float, string).
@@ -1895,10 +1969,20 @@ class wpdb {
 
                $fields = $conditions = $values = array();
                foreach ( $data as $field => $value ) {
+                       if ( is_null( $value['value'] ) ) {
+                               $fields[] = "`$field` = NULL";
+                               continue;
+                       }
+
                        $fields[] = "`$field` = " . $value['format'];
                        $values[] = $value['value'];
                }
                foreach ( $where as $field => $value ) {
+                       if ( is_null( $value['value'] ) ) {
+                               $conditions[] = "`$field` IS NULL";
+                               continue;
+                       }
+
                        $conditions[] = "`$field` = " . $value['format'];
                        $values[] = $value['value'];
                }
@@ -1927,6 +2011,7 @@ class wpdb {
         * @param array        $where        A named array of WHERE clauses (in column => value pairs).
         *                                   Multiple clauses will be joined with ANDs.
         *                                   Both $where columns and $where values should be "raw".
+        *                                   Sending a null value will create an IS NULL comparison - the corresponding format will be ignored in this case.
         * @param array|string $where_format Optional. An array of formats to be mapped to each of the values in $where.
         *                                   If string, that format will be used for all of the items in $where.
         *                                   A format is one of '%d', '%f', '%s' (integer, float, string).
@@ -1945,6 +2030,11 @@ class wpdb {
 
                $conditions = $values = array();
                foreach ( $where as $field => $value ) {
+                       if ( is_null( $value['value'] ) ) {
+                               $conditions[] = "`$field` IS NULL";
+                               continue;
+                       }
+
                        $conditions[] = "`$field` = " . $value['format'];
                        $values[] = $value['value'];
                }
@@ -2049,8 +2139,10 @@ class wpdb {
        protected function process_field_charsets( $data, $table ) {
                foreach ( $data as $field => $value ) {
                        if ( '%d' === $value['format'] || '%f' === $value['format'] ) {
-                               // We can skip this field if we know it isn't a string.
-                               // This checks %d/%f versus ! %s because it's sprintf() could take more.
+                               /*
+                                * We can skip this field if we know it isn't a string.
+                                * This checks %d/%f versus ! %s because its sprintf() could take more.
+                                */
                                $value['charset'] = false;
                        } else {
                                $value['charset'] = $this->get_col_charset( $table, $field );
@@ -2079,8 +2171,10 @@ class wpdb {
        protected function process_field_lengths( $data, $table ) {
                foreach ( $data as $field => $value ) {
                        if ( '%d' === $value['format'] || '%f' === $value['format'] ) {
-                               // We can skip this field if we know it isn't a string.
-                               // This checks %d/%f versus ! %s because it's sprintf() could take more.
+                               /*
+                                * We can skip this field if we know it isn't a string.
+                                * This checks %d/%f versus ! %s because its sprintf() could take more.
+                                */
                                $value['length'] = false;
                        } else {
                                $value['length'] = $this->get_col_length( $table, $field );
@@ -2249,7 +2343,7 @@ class wpdb {
                } elseif ( $output == ARRAY_A || $output == ARRAY_N ) {
                        // Return an integer-keyed array of...
                        if ( $this->last_result ) {
-                               foreach( (array) $this->last_result as $row ) {
+                               foreach ( (array) $this->last_result as $row ) {
                                        if ( $output == ARRAY_N ) {
                                                // ...integer-keyed row arrays
                                                $new_array[] = array_values( get_object_vars( $row ) );
@@ -2401,7 +2495,7 @@ class wpdb {
                }
 
                // Skip this entirely if this isn't a MySQL database.
-               if ( false === $this->is_mysql ) {
+               if ( empty( $this->is_mysql ) ) {
                        return false;
                }
 
@@ -2450,7 +2544,7 @@ class wpdb {
                $columnkey = strtolower( $column );
 
                // Skip this entirely if this isn't a MySQL database.
-               if ( false === $this->is_mysql ) {
+               if ( empty( $this->is_mysql ) ) {
                        return false;
                }
 
@@ -2482,47 +2576,45 @@ class wpdb {
                                        'type'   => 'char',
                                        'length' => (int) $length,
                                );
-                               break;
+
                        case 'binary':
                        case 'varbinary':
                                return array(
                                        'type'   => 'byte',
                                        'length' => (int) $length,
                                );
-                               break;
+
                        case 'tinyblob':
                        case 'tinytext':
                                return array(
                                        'type'   => 'byte',
                                        'length' => 255,        // 2^8 - 1
                                );
-                               break;
+
                        case 'blob':
                        case 'text':
                                return array(
                                        'type'   => 'byte',
                                        'length' => 65535,      // 2^16 - 1
                                );
-                               break;
+
                        case 'mediumblob':
                        case 'mediumtext':
                                return array(
                                        'type'   => 'byte',
                                        'length' => 16777215,   // 2^24 - 1
                                );
-                               break;
+
                        case 'longblob':
                        case 'longtext':
                                return array(
                                        'type'   => 'byte',
                                        'length' => 4294967295, // 2^32 - 1
                                );
-                               break;
+
                        default:
                                return false;
                }
-
-               return false;
        }
 
        /**
@@ -2594,7 +2686,7 @@ class wpdb {
                }
 
                // If any of the columns don't have one of these collations, it needs more sanity checking.
-               foreach( $this->col_meta[ $table ] as $col ) {
+               foreach ( $this->col_meta[ $table ] as $col ) {
                        if ( empty( $col->Collation ) ) {
                                continue;
                        }
@@ -2721,11 +2813,21 @@ class wpdb {
                                                $charset = $value['charset'];
                                        }
 
+                                       if ( $this->charset ) {
+                                               $connection_charset = $this->charset;
+                                       } else {
+                                               if ( $this->use_mysqli ) {
+                                                       $connection_charset = mysqli_character_set_name( $this->dbh );
+                                               } else {
+                                                       $connection_charset = mysql_client_encoding();
+                                               }
+                                       }
+
                                        if ( is_array( $value['length'] ) ) {
-                                               $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING {$this->charset} )", $value['value'], $value['length']['length'] );
+                                               $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING $connection_charset )", $value['value'], $value['length']['length'] );
                                        } else if ( 'binary' !== $charset ) {
                                                // If we don't have a length, there's no need to convert binary - it will always return the same result.
-                                               $queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING {$this->charset} )", $value['value'] );
+                                               $queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING $connection_charset )", $value['value'] );
                                        }
 
                                        unset( $data[ $col ]['db'] );
@@ -2870,7 +2972,7 @@ class wpdb {
                                . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?'
                                . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
                                . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
-                               . ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
+                               . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
                        return str_replace( '`', '', $maybe[1] );
                }
 
@@ -2878,7 +2980,7 @@ class wpdb {
                if ( preg_match( '/^\s*(?:'
                                . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
                                . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
-                               . ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
+                               . ')\W((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
                        return str_replace( '`', '', $maybe[1] );
                }
 
@@ -2897,7 +2999,7 @@ class wpdb {
                                . '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE'
                                . '|(?:GRANT|REVOKE).*ON\s+TABLE'
                                . '|SHOW\s+(?:.*FROM|.*TABLE)'
-                               . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
+                               . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
                        return str_replace( '`', '', $maybe[1] );
                }
 
@@ -2916,14 +3018,14 @@ class wpdb {
                        return;
 
                if ( $this->use_mysqli ) {
-                       $num_fields = @mysqli_num_fields( $this->result );
+                       $num_fields = mysqli_num_fields( $this->result );
                        for ( $i = 0; $i < $num_fields; $i++ ) {
-                               $this->col_info[ $i ] = @mysqli_fetch_field( $this->result );
+                               $this->col_info[ $i ] = mysqli_fetch_field( $this->result );
                        }
                } else {
-                       $num_fields = @mysql_num_fields( $this->result );
+                       $num_fields = mysql_num_fields( $this->result );
                        for ( $i = 0; $i < $num_fields; $i++ ) {
-                               $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i );
+                               $this->col_info[ $i ] = mysql_fetch_field( $this->result, $i );
                        }
                }
        }
@@ -2944,7 +3046,7 @@ class wpdb {
                        if ( $col_offset == -1 ) {
                                $i = 0;
                                $new_array = array();
-                               foreach( (array) $this->col_info as $col ) {
+                               foreach ( (array) $this->col_info as $col ) {
                                        $new_array[$i] = $col->{$info_type};
                                        $i++;
                                }
@@ -2991,15 +3093,46 @@ class wpdb {
         */
        public function bail( $message, $error_code = '500' ) {
                if ( !$this->show_errors ) {
-                       if ( class_exists( 'WP_Error' ) )
+                       if ( class_exists( 'WP_Error', false ) ) {
                                $this->error = new WP_Error($error_code, $message);
-                       else
+                       } else {
                                $this->error = $message;
+                       }
                        return false;
                }
                wp_die($message);
        }
 
+
+       /**
+        * Closes the current database connection.
+        *
+        * @since 4.5.0
+        * @access public
+        *
+        * @return bool True if the connection was successfully closed, false if it wasn't,
+        *              or the connection doesn't exist.
+        */
+       public function close() {
+               if ( ! $this->dbh ) {
+                       return false;
+               }
+
+               if ( $this->use_mysqli ) {
+                       $closed = mysqli_close( $this->dbh );
+               } else {
+                       $closed = mysql_close( $this->dbh );
+               }
+
+               if ( $closed ) {
+                       $this->dbh = null;
+                       $this->ready = false;
+                       $this->has_connected = false;
+               }
+
+               return $closed;
+       }
+
        /**
         * Whether MySQL database is at least the required minimum version.
         *
@@ -3022,9 +3155,10 @@ class wpdb {
         *
         * Called when WordPress is generating the table scheme.
         *
+        * Use `wpdb::has_cap( 'collation' )`.
+        *
         * @since 2.5.0
-        * @deprecated 3.5.0
-        * @deprecated Use wpdb::has_cap( 'collation' )
+        * @deprecated 3.5.0 Use wpdb::has_cap()
         *
         * @return bool True if collation is supported, false if version does not
         */
@@ -3114,7 +3248,7 @@ class wpdb {
        }
 
        /**
-        * The database version number.
+        * Retrieves the MySQL server version.
         *
         * @since 2.7.0
         *