wpdb::__construct
Connects to the database server and selects a database.
Does the actual setting up of the class properties and connection to the database.
Method of the class: wpdb{}
No Hooks.
Returns
null. Nothing (null).
Usage
global $wpdb; $wpdb->__construct( $dbuser, $dbpassword, $dbname, $dbhost );
- $dbuser(string) (required)
- Database user.
- $dbpassword(string) (required)
Database password.
It has the attribute #[\SensitiveParameter], which hides the value of the parameter from logs. It is used to protect sensitive data (for example, passwords). Documentation.
- $dbname(string) (required)
- Database name.
- $dbhost(string) (required)
- Database host.
Changelog
| Since 2.0.8 | Introduced. |
wpdb::__construct() wpdb:: construct code WP 7.0
public function __construct(
$dbuser,
#[\SensitiveParameter]
$dbpassword,
$dbname,
$dbhost
) {
if ( WP_DEBUG && WP_DEBUG_DISPLAY ) {
$this->show_errors();
}
$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' ) ) {
return;
}
$this->db_connect();
}