X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/48ab98cb1779cf2088c1351ac3dd3d0da6fb31d3..849f15aeed7a5e39314057bdc0064d8edd60dd7d:/wp-includes/wp-db.php diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index f30ad791..1656df7b 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -567,7 +567,7 @@ class wpdb { * the actual setting up of the class properties and connection * to the database. * - * @link http://core.trac.wordpress.org/ticket/3354 + * @link https://core.trac.wordpress.org/ticket/3354 * @since 2.0.8 * * @param string $dbuser MySQL database user @@ -632,7 +632,7 @@ class wpdb { * @return mixed The private member */ public function __get( $name ) { - if ( 'col_info' == $name ) + if ( 'col_info' === $name ) $this->load_col_info(); return $this->$name; @@ -700,8 +700,8 @@ class wpdb { * @since 3.1.0 * * @param resource $dbh The resource given by mysql_connect - * @param string $charset The character set (optional) - * @param string $collate The collation (optional) + * @param string $charset Optional. The character set. Default null. + * @param string $collate Optional. The collation. Default null. */ public function set_charset( $dbh, $charset = null, $collate = null ) { if ( ! isset( $charset ) ) @@ -777,8 +777,6 @@ class wpdb { * * @since 3.9.0 * - * @see wpdb::$incompatible_modes - * * @param array $incompatible_modes An array of incompatible modes. */ $incompatible_modes = (array) apply_filters( 'incompatible_sql_modes', $this->incompatible_modes ); @@ -844,7 +842,7 @@ class wpdb { * @access public * @param int $blog_id * @param int $site_id Optional. - * @return string previous blog id + * @return int previous blog id */ public function set_blog_id( $blog_id, $site_id = 0 ) { if ( ! empty( $site_id ) ) @@ -867,7 +865,6 @@ class wpdb { /** * Gets blog prefix. * - * @uses is_multisite() * @since 3.0.0 * @param int $blog_id Optional. * @return string Blog prefix. @@ -906,7 +903,6 @@ class wpdb { * @uses wpdb::$old_tables * @uses wpdb::$global_tables * @uses wpdb::$ms_global_tables - * @uses is_multisite() * * @param string $scope Optional. Can be all, global, ms_global, blog, or old tables. Defaults to all. * @param bool $prefix Optional. Whether to include table prefixes. Default true. If blog @@ -1042,7 +1038,11 @@ class wpdb { } $class = get_class( $this ); - _doing_it_wrong( $class, "$class must set a database connection for use with escaping.", E_USER_NOTICE ); + if ( function_exists( '__' ) ) { + _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 ); + } return addslashes( $string ); } @@ -1134,10 +1134,8 @@ class wpdb { * * Both %d and %s should be left unquoted in the query string. * - * - * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", 'foo', 1337 ) - * wpdb::prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' ); - * + * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", 'foo', 1337 ) + * wpdb::prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' ); * * @link http://php.net/sprintf Description of syntax. * @since 2.3.0 @@ -1206,7 +1204,7 @@ class wpdb { * @global array $EZSQL_ERROR Stores error information of query and error string * * @param string $str The error to display - * @return bool False if the showing of errors is disabled. + * @return false|null False if the showing of errors is disabled. */ public function print_error( $str = '' ) { global $EZSQL_ERROR; @@ -1320,12 +1318,21 @@ class wpdb { $this->rows_affected = $this->num_rows = 0; $this->last_error = ''; - if ( is_resource( $this->result ) ) { - if ( $this->use_mysqli ) { - mysqli_free_result( $this->result ); - } else { - mysql_free_result( $this->result ); + if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { + mysqli_free_result( $this->result ); + $this->result = null; + + // Sanity check before using the handle + if ( empty( $this->dbh ) || !( $this->dbh instanceof mysqli ) ) { + return; } + + // Clear out any results from a multi-query + while ( mysqli_more_results( $this->dbh ) ) { + mysqli_next_result( $this->dbh ); + } + } else if ( is_resource( $this->result ) ) { + mysql_free_result( $this->result ); } } @@ -1339,7 +1346,7 @@ class wpdb { * @since 3.9.0 $allow_bail parameter added. * * @param bool $allow_bail Optional. Allows the function to bail. Default true. - * @return bool True with a successful connection, false on failure. + * @return null|bool True with a successful connection, false on failure. */ public function db_connect( $allow_bail = true ) { @@ -1458,7 +1465,7 @@ class wpdb { * @since 3.9.0 * * @param bool $allow_bail Optional. Allows the function to bail. Default true. - * @return bool True if the connection is up. + * @return bool|null True if the connection is up. */ public function check_connection( $allow_bail = true ) { if ( $this->use_mysqli ) { @@ -1533,8 +1540,9 @@ class wpdb { * @return int|false Number of rows affected/selected or false on error */ public function query( $query ) { - if ( ! $this->ready ) + if ( ! $this->ready ) { return false; + } /** * Filter the database query. @@ -1613,12 +1621,12 @@ class wpdb { $return_val = $this->rows_affected; } else { $num_rows = 0; - if ( $this->use_mysqli ) { + if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { while ( $row = @mysqli_fetch_object( $this->result ) ) { $this->last_result[$num_rows] = $row; $num_rows++; } - } else { + } else if ( is_resource( $this->result ) ) { while ( $row = @mysql_fetch_object( $this->result ) ) { $this->last_result[$num_rows] = $row; $num_rows++; @@ -1664,10 +1672,8 @@ class wpdb { /** * Insert a row into a table. * - * - * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 'bar' ) ) - * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) - * + * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 'bar' ) ) + * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) * * @since 2.5.0 * @see wpdb::prepare() @@ -1687,10 +1693,8 @@ class wpdb { /** * Replace a row into a table. * - * - * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 'bar' ) ) - * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) - * + * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 'bar' ) ) + * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) * * @since 3.0.0 * @see wpdb::prepare() @@ -1748,10 +1752,8 @@ class wpdb { /** * Update a row in the table * - * - * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 'bar' ), array( 'ID' => 1 ) ) - * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) ) - * + * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 'bar' ), array( 'ID' => 1 ) ) + * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) ) * * @since 2.5.0 * @see wpdb::prepare() @@ -1800,10 +1802,8 @@ class wpdb { /** * Delete a row in the table * - * - * wpdb::delete( 'table', array( 'ID' => 1 ) ) - * wpdb::delete( 'table', array( 'ID' => 1 ), array( '%d' ) ) - * + * wpdb::delete( 'table', array( 'ID' => 1 ) ) + * wpdb::delete( 'table', array( 'ID' => 1 ), array( '%d' ) ) * * @since 3.4.0 * @see wpdb::prepare() @@ -1839,7 +1839,6 @@ class wpdb { return $this->query( $this->prepare( $sql, $where ) ); } - /** * Retrieve one variable from the database. * @@ -1856,8 +1855,10 @@ class wpdb { */ public function get_var( $query = null, $x = 0, $y = 0 ) { $this->func_call = "\$db->get_var(\"$query\", $x, $y)"; - if ( $query ) + + if ( $query ) { $this->query( $query ); + } // Extract var out of cached results based x,y vals if ( !empty( $this->last_result[$y] ) ) { @@ -1883,10 +1884,11 @@ class wpdb { */ public function get_row( $query = null, $output = OBJECT, $y = 0 ) { $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; - if ( $query ) + if ( $query ) { $this->query( $query ); - else + } else { return null; + } if ( !isset( $this->last_result[$y] ) ) return null; @@ -1919,8 +1921,9 @@ class wpdb { * @return array Database query result. Array indexed from 0 by SQL result row number. */ public function get_col( $query = null , $x = 0 ) { - if ( $query ) + if ( $query ) { $this->query( $query ); + } $new_array = array(); // Extract the column values @@ -1946,10 +1949,11 @@ class wpdb { public function get_results( $query = null, $output = OBJECT ) { $this->func_call = "\$db->get_results(\"$query\", $output)"; - if ( $query ) + if ( $query ) { $this->query( $query ); - else + } else { return null; + } $new_array = array(); if ( $output == OBJECT ) { @@ -2040,7 +2044,7 @@ class wpdb { * * @since 1.5.0 * - * @return true + * @return bool */ public function timer_start() { $this->time_start = microtime( true ); @@ -2134,10 +2138,14 @@ class wpdb { * Determine if a database supports a particular feature. * * @since 2.7.0 + * @since 4.1.0 Support was added for the 'utf8mb4' feature. + * * @see wpdb::db_version() * - * @param string $db_cap The feature to check for. - * @return bool + * @param string $db_cap The feature to check for. Accepts 'collation', + * 'group_concat', 'subqueries', 'set_charset', + * or 'utf8mb4'. + * @return bool Whether the database feature is supported, false otherwise. */ public function has_cap( $db_cap ) { $version = $this->db_version(); @@ -2149,7 +2157,9 @@ class wpdb { return version_compare( $version, '4.1', '>=' ); case 'set_charset' : return version_compare( $version, '5.0.7', '>=' ); - }; + case 'utf8mb4' : // @since 4.1.0 + return version_compare( $version, '5.5.3', '>=' ); + } return false; } @@ -2173,7 +2183,7 @@ class wpdb { * * @since 2.7.0 * - * @return false|string false on failure, version number on success + * @return null|string Null on failure, version number on success. */ public function db_version() { if ( $this->use_mysqli ) {