wpdb::__construct PHP Méthode

__construct() public méthode

PHP5 style constructor for compatibility with PHP5. Does the actual setting up of the class properties and connection to the database.
public __construct ( string $dbuser, string $dbpassword, string $dbname, string $dbhost )
$dbuser string MySQL database user
$dbpassword string MySQL database password
$dbname string MySQL database name
$dbhost string MySQL database host
    public function __construct($dbuser, $dbpassword, $dbname, $dbhost)
    {
        register_shutdown_function([$this, '__destruct']);
        if (WP_DEBUG && WP_DEBUG_DISPLAY) {
            $this->show_errors();
        }
        /* Use ext/mysqli if it exists and:
         *  - WP_USE_EXT_MYSQL is defined as false, or
         *  - We are a development version of WordPress, or
         *  - We are running PHP 5.5 or greater, or
         *  - ext/mysql is not loaded.
         */
        if (function_exists('mysqli_connect')) {
            if (defined('WP_USE_EXT_MYSQL')) {
                $this->use_mysqli = !WP_USE_EXT_MYSQL;
            } elseif (version_compare(phpversion(), '5.5', '>=') || !function_exists('mysql_connect')) {
                $this->use_mysqli = true;
            } elseif (false !== strpos($GLOBALS['wp_version'], '-')) {
                $this->use_mysqli = true;
            }
        }
        $this->init_charset();
        $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();
    }

Usage Example

Exemple #1
0
 /**
  * Class constructor
  */
 function __construct($dbuser, $dbpassword, $dbname, $dbhost)
 {
     foreach ($this->qm_php_vars as $setting => &$val) {
         $val = ini_get($setting);
     }
     parent::__construct($dbuser, $dbpassword, $dbname, $dbhost);
 }
All Usage Examples Of wpdb::__construct