wpdb::__construct( string $dbuser, string $dbpassword, string $dbname, string $dbhost )

Connects to the database server and selects a database.

Description Description

PHP5 style constructor for compatibility with PHP5. Does the actual setting up of the class properties and connection to the database.

Top ↑

Parameters Parameters


(string) (Required) MySQL database user.


(string) (Required) MySQL database password.


(string) (Required) MySQL database name.


(string) (Required) MySQL database host.

Top ↑

Source Source

File: wp-includes/wp-db.php

	public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {

		// Use ext/mysqli if it exists unless WP_USE_EXT_MYSQL is defined as true.
		if ( function_exists( 'mysqli_connect' ) ) {
			$this->use_mysqli = true;

			if ( defined( 'WP_USE_EXT_MYSQL' ) ) {
				$this->use_mysqli = ! WP_USE_EXT_MYSQL;

		$this->dbuser     = $dbuser;
		$this->dbpassword = $dbpassword;
		$this->dbname     = $dbname;
		$this->dbhost     = $dbhost;

		// wp-config.php creation will manually connect when ready.
		if ( defined( 'WP_SETUP_CONFIG' ) ) {


Top ↑

Changelog Changelog

Version Description
2.0.8 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.