Ticket #7081: wp-db.patch
| File wp-db.patch, 3.7 KB (added by , 18 years ago) |
|---|
-
wp-db.
old new 44 44 var $charset; 45 45 var $collate; 46 46 47 // Our Database Connection Details 48 var $dbuser = ''; 49 var $dbpassword = ''; 50 var $dbname = ''; 51 var $dbhost = ''; 52 47 53 /** 48 54 * Connects to the database server and selects a database 49 55 * @param string $dbuser … … 67 73 if ( defined('DB_COLLATE') ) 68 74 $this->collate = DB_COLLATE; 69 75 70 $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true); 76 $this->dbuser = $dbuser; 77 $this->dbpassword = $dbpassword; 78 $this->dbname = $dbname; 79 $this->dbhost = $dbhost; 80 81 if (defined('DB_SLAVE_ENABLED')) 82 { 83 if (defined('DB_SLAVE_USERNAME') && 84 defined('DB_SLAVE_PASSWORD') && 85 defined('DB_SLAVE_HOSTNAME') 86 ) 87 { 88 $this->slave_username = DB_SLAVE_USERNAME; 89 $this->slave_password = DB_SLAVE_PASSWORD; 90 $this->slave_hostname = DB_SLAVE_HOSTNAME; 91 } 92 } 93 94 $this->ready = true; 95 } 96 97 function __destruct() { 98 return true; 99 } 100 101 function create_database_connection($readOnly = false) 102 { 103 if ($this->dbh && $this->read_only == $readOnly) 104 return true; 105 106 if (!$this->dbhost || !$this->dbuser || !$this->dbpassword || !$this->dbname) 107 { 108 $this->bail(" 109 <h1>Error establishing a database connection</h1> 110 <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> 111 <ul> 112 <li>Are you sure you have the correct username and password?</li> 113 <li>Are you sure that you have typed the correct hostname?</li> 114 <li>Are you sure that the database server is running?</li> 115 </ul> 116 <p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='http://wordpress.org/support/'>WordPress Support Forums</a>.</p> 117 "); 118 } 119 120 if (defined('DB_SLAVE_ENABLED') && $readOnly) 121 { 122 $this->dbh = @mysql_connect($this->slave_hostname, $this->slave_username, $this->slave_password, true); 123 $this->read_only = true; 124 } 125 else 126 { 127 $this->dbh = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, true); 128 $this->read_only = false; 129 } 130 71 131 if (!$this->dbh) { 72 132 $this->bail(" 73 133 <h1>Error establishing a database connection</h1> … … 87 147 if ( !empty($this->charset) && version_compare(mysql_get_server_info($this->dbh), '4.1.0', '>=') ) 88 148 $this->query("SET NAMES '$this->charset'"); 89 149 90 $this->select($dbname); 91 } 150 $this->select($this->dbname); 92 151 93 function __destruct() {94 return true;95 152 } 96 153 97 154 function set_prefix($prefix) { … … 272 329 if (SAVEQUERIES) 273 330 $this->timer_start(); 274 331 332 $readOnly = $this->isSelectquery($query); 333 $this->create_database_connection($readOnly); 275 334 $this->result = @mysql_query($query, $this->dbh); 276 335 ++$this->num_queries; 277 336 … … 527 586 { 528 587 global $wp_version; 529 588 // Make sure the server has MySQL 4.0 589 $this->create_database_connection(true); 530 590 $mysql_version = preg_replace('|[^0-9\.]|', '', @mysql_get_server_info($this->dbh)); 531 591 if ( version_compare($mysql_version, '4.0.0', '<') ) 532 592 return new WP_Error('database_version',sprintf(__('<strong>ERROR</strong>: WordPress %s requires MySQL 4.0.0 or higher'), $wp_version)); … … 538 598 */ 539 599 function supports_collation() 540 600 { 601 $this->create_database_connection(true); 541 602 return ( version_compare(mysql_get_server_info($this->dbh), '4.1.0', '>=') ); 542 603 } 543 604 … … 569 630 return $caller; 570 631 } 571 632 633 function isSelectquery($query) { 634 $query = ltrim($query); 635 if (preg_match('/^SELECT/iS', $query)) 636 { 637 return true; 638 } 639 return false; 640 } 572 641 } 573 642 574 643 if ( ! isset($wpdb) )
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)