On this page
wpdb::__construct( string $dbuser, string $dbpassword, string $dbname, string $dbhost )
Connects to the database server and selects a database.
Description
Does the actual setting up of the class properties and connection to the database.
Parameters
$dbuserstring Required-
Database user.
$dbpasswordstring Required-
Database password.
$dbnamestring Required-
Database name.
$dbhoststring Required-
Database host.
Source
File: wp-includes/class-wpdb.php. View all references
public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
if ( WP_DEBUG && WP_DEBUG_DISPLAY ) {
$this->show_errors();
}
// Use the `mysqli` extension 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' ) ) {
return;
}
$this->db_connect();
}
Related
Uses
| Uses | Description |
|---|---|
| wpdb::show_errors() wp-includes/class-wpdb.php | Enables showing of database errors. |
| wpdb::db_connect() wp-includes/class-wpdb.php | Connects to and selects database. |
Used By
| Used By | Description |
|---|---|
| require_wp_db() wp-includes/load.php | Load the database class file and instantiate the |
Changelog
| Version | Description |
|---|---|
| 2.0.8 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wpdb/__construct