Ticket #6305: wp-db.diff
| File wp-db.diff, 2.6 KB (added by , 18 years ago) |
|---|
-
wp-includes/wp-db.php
43 43 'postmeta', 'terms', 'term_taxonomy', 'term_relationships'); 44 44 var $charset; 45 45 var $collate; 46 var $db_user; 47 var $db_password; 48 var $db_name; 49 var $db_host; 46 50 47 51 /** 48 52 * Connects to the database server and selects a database … … 67 71 if ( defined('DB_COLLATE') ) 68 72 $this->collate = DB_COLLATE; 69 73 70 $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true); 71 if (!$this->dbh) { 74 $this->db_user = $dbuser; 75 $this->db_password = $dbpassword; 76 $this->db_name = $dbname; 77 $this->db_host = $dbhost; 78 79 $this->connect_to_db(); 80 } 81 82 function __destruct() { 83 return true; 84 } 85 86 function connect_to_db() { 87 $this->dbh = @mysql_connect($this->db_host, $this->db_user, $this->db_password, true); 88 if ( !$this->dbh ) { 72 89 $this->bail(" 73 90 <h1>Error establishing a database connection</h1> 74 91 <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> … … 87 104 if ( !empty($this->charset) && version_compare(mysql_get_server_info($this->dbh), '4.1.0', '>=') ) 88 105 $this->query("SET NAMES '$this->charset'"); 89 106 90 $this->select($ dbname);107 $this->select($this->db_name); 91 108 } 92 109 93 function __destruct() { 94 return true; 110 function check_connection() { 111 $maxcount = 2; 112 $count = 0; 113 114 $ping = mysql_ping( $this->dbh ) ; 115 116 while ( !$ping && $count < $maxcount ) { 117 @mysql_close($this->dbh); 118 sleep(2); 119 if ($this->connect_to_db() ) 120 { 121 $ping = mysql_ping( $this->dbh ) ; 122 123 if ( $ping ) 124 break; 125 } 126 sleep(2); 127 $count++; 128 } 129 130 if ( !$ping ) 131 $this->bail('Lost connection to server'); 95 132 } 96 133 97 134 function set_prefix($prefix) { 98 135 99 136 if ( preg_match('|[^a-z0-9_]|i', $prefix) ) … … 280 317 281 318 // If there is an error then take note of it.. 282 319 if ( $this->last_error = mysql_error($this->dbh) ) { 283 $this->print_error(); 284 return false; 320 $errno = mysql_errno(); 321 if ( 2006 == $errno || 2013 == $errno ) { 322 $this->check_connection(); 323 $this->result = @mysql_query($query, $this->dbh); 324 if ( $this->last_error = mysql_error($this->dbh) ) { 325 $this->print_error(); 326 return false; 327 } 328 } else { 329 $this->print_error(); 330 return false; 331 } 285 332 } 286 333 287 334 if ( preg_match("/^\\s*(insert|delete|update|replace) /i",$query) ) {