Make WordPress Core

Ticket #3012: 3012.diff

File 3012.diff, 2.4 KB (added by mdawaffe, 20 years ago)

Lazy Load from Jay Pipes

  • wp-db.php

     
    2020        var $last_query;
    2121        var $col_info;
    2222        var $queries;
     23        var $user;
     24        var $password;
     25        var $database;
     26        var $host;
    2327
    2428        // Our tables
    2529        var $posts;
     
    3741        var $postmeta;
    3842
    3943        // ==================================================================
    40         //      DB Constructor - connects to the server and selects a database
     44        //      DB Constructor - do nothing: lazy load on execution of query
    4145
    4246        function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
    43                 $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
     47                $this->user = $dbuser;
     48                $this->password = $dbpassword;
     49                $this->database = $dbname;
     50                $this->host = $dbhost;
     51        }
     52
     53        // ==================================================================
     54        //      connects to the server and selects a database
     55
     56        function connect() {
     57                $this->dbh = @mysql_connect($this->host, $this->user, $this->password);
    4458                if (!$this->dbh) {
    4559                        $this->bail("
    4660<h1>Error establishing a database connection</h1>
    47 <p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>$dbhost</code>. This could mean your host's database server is down.</p>
     61<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>$this->host</code>. This could mean your host's database server is down.</p>
    4862<ul>
    4963        <li>Are you sure you have the correct username and password?</li>
    5064        <li>Are you sure that you have typed the correct hostname?</li>
     
    5468");
    5569                }
    5670
    57                 $this->select($dbname);
     71                $this->select();
    5872        }
    5973
    6074        // ==================================================================
    6175        //      Select a DB (if another one needs to be selected)
    6276
    63         function select($db) {
     77        function select($db = false) {
     78                if ( !$db )
     79                        $db = $this->database;
    6480                if (!@mysql_select_db($db, $this->dbh)) {
    6581                        $this->bail("
    6682<h1>Can&#8217;t select database</h1>
     
    145161                if (SAVEQUERIES)
    146162                        $this->timer_start();
    147163
     164                // Lazy load the database
     165                if ( !$this->dbh )
     166                        $this->connect();
     167
    148168                $this->result = @mysql_query($query, $this->dbh);
    149169                ++$this->num_queries;
    150170
     
    364384}
    365385
    366386$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    367 ?>
    368  No newline at end of file
     387?>