wp/wp-includes/class-wpdb.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   747 	 * @param string $dbuser     Database user.
   747 	 * @param string $dbuser     Database user.
   748 	 * @param string $dbpassword Database password.
   748 	 * @param string $dbpassword Database password.
   749 	 * @param string $dbname     Database name.
   749 	 * @param string $dbname     Database name.
   750 	 * @param string $dbhost     Database host.
   750 	 * @param string $dbhost     Database host.
   751 	 */
   751 	 */
   752 	public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
   752 	public function __construct(
       
   753 		$dbuser,
       
   754 		#[\SensitiveParameter]
       
   755 		$dbpassword,
       
   756 		$dbname,
       
   757 		$dbhost
       
   758 	) {
   753 		if ( WP_DEBUG && WP_DEBUG_DISPLAY ) {
   759 		if ( WP_DEBUG && WP_DEBUG_DISPLAY ) {
   754 			$this->show_errors();
   760 			$this->show_errors();
   755 		}
   761 		}
   756 
   762 
   757 		$this->dbuser     = $dbuser;
   763 		$this->dbuser     = $dbuser;
  2112 	 *
  2118 	 *
  2113 	 * @param bool $allow_bail Optional. Allows the function to bail. Default true.
  2119 	 * @param bool $allow_bail Optional. Allows the function to bail. Default true.
  2114 	 * @return bool|void True if the connection is up.
  2120 	 * @return bool|void True if the connection is up.
  2115 	 */
  2121 	 */
  2116 	public function check_connection( $allow_bail = true ) {
  2122 	public function check_connection( $allow_bail = true ) {
  2117 		if ( ! empty( $this->dbh ) && mysqli_ping( $this->dbh ) ) {
  2123 		// Check if the connection is alive.
       
  2124 		if ( ! empty( $this->dbh ) && mysqli_query( $this->dbh, 'DO 1' ) !== false ) {
  2118 			return true;
  2125 			return true;
  2119 		}
  2126 		}
  2120 
  2127 
  2121 		$error_reporting = false;
  2128 		$error_reporting = false;
  2122 
  2129 
  2403 	 */
  2410 	 */
  2404 	public function placeholder_escape() {
  2411 	public function placeholder_escape() {
  2405 		static $placeholder;
  2412 		static $placeholder;
  2406 
  2413 
  2407 		if ( ! $placeholder ) {
  2414 		if ( ! $placeholder ) {
  2408 			// If ext/hash is not present, compat.php's hash_hmac() does not support sha256.
       
  2409 			$algo = function_exists( 'hash' ) ? 'sha256' : 'sha1';
       
  2410 			// Old WP installs may not have AUTH_SALT defined.
  2415 			// Old WP installs may not have AUTH_SALT defined.
  2411 			$salt = defined( 'AUTH_SALT' ) && AUTH_SALT ? AUTH_SALT : (string) rand();
  2416 			$salt = defined( 'AUTH_SALT' ) && AUTH_SALT ? AUTH_SALT : (string) rand();
  2412 
  2417 
  2413 			$placeholder = '{' . hash_hmac( $algo, uniqid( $salt, true ), $salt ) . '}';
  2418 			$placeholder = '{' . hash_hmac( 'sha256', uniqid( $salt, true ), $salt ) . '}';
  2414 		}
  2419 		}
  2415 
  2420 
  2416 		/*
  2421 		/*
  2417 		 * Add the filter to remove the placeholder escaper. Uses priority 0, so that anything
  2422 		 * Add the filter to remove the placeholder escaper. Uses priority 0, so that anything
  2418 		 * else attached to this filter will receive the query with the placeholder string removed.
  2423 		 * else attached to this filter will receive the query with the placeholder string removed.
  3980 	/**
  3985 	/**
  3981 	 * Determines whether MySQL database is at least the required minimum version.
  3986 	 * Determines whether MySQL database is at least the required minimum version.
  3982 	 *
  3987 	 *
  3983 	 * @since 2.5.0
  3988 	 * @since 2.5.0
  3984 	 *
  3989 	 *
  3985 	 * @global string $wp_version             The WordPress version string.
       
  3986 	 * @global string $required_mysql_version The required MySQL version string.
  3990 	 * @global string $required_mysql_version The required MySQL version string.
  3987 	 * @return void|WP_Error
  3991 	 * @return void|WP_Error
  3988 	 */
  3992 	 */
  3989 	public function check_database_version() {
  3993 	public function check_database_version() {
  3990 		global $wp_version, $required_mysql_version;
  3994 		global $required_mysql_version;
       
  3995 		$wp_version = wp_get_wp_version();
       
  3996 
  3991 		// Make sure the server has the required MySQL version.
  3997 		// Make sure the server has the required MySQL version.
  3992 		if ( version_compare( $this->db_version(), $required_mysql_version, '<' ) ) {
  3998 		if ( version_compare( $this->db_version(), $required_mysql_version, '<' ) ) {
  3993 			/* translators: 1: WordPress version number, 2: Minimum required MySQL version number. */
  3999 			/* translators: 1: WordPress version number, 2: Minimum required MySQL version number. */
  3994 			return new WP_Error( 'database_version', sprintf( __( '<strong>Error:</strong> WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version ) );
  4000 			return new WP_Error( 'database_version', sprintf( __( '<strong>Error:</strong> WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version ) );
  3995 		}
  4001 		}