Ticket #6305: wpdb_ping.diff
| File wpdb_ping.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 $this->connect_to_db(); 119 120 $ping = mysql_ping( $this->dbh ) ; 121 122 if ( $ping ) 123 break; 124 125 sleep(2); 126 $count++; 127 } 128 129 if ( !$ping ) 130 $this->bail('Lost connection to server'); 95 131 } 96 132 97 133 function set_prefix($prefix) { 98 134 99 135 if ( preg_match('|[^a-z0-9_]|i', $prefix) ) … … 280 316 281 317 // If there is an error then take note of it.. 282 318 if ( $this->last_error = mysql_error($this->dbh) ) { 283 $this->print_error(); 284 return false; 319 $errno = mysql_errno(); 320 if ( 2006 == $errno || 2013 == $errno ) { 321 $this->check_connection(); 322 $this->result = @mysql_query($query, $this->dbh); 323 if ( $this->last_error = mysql_error($this->dbh) ) { 324 $this->print_error(); 325 return false; 326 } 327 } else { 328 $this->print_error(); 329 return false; 330 } 285 331 } 286 332 287 333 if ( preg_match("/^\\s*(insert|delete|update|replace) /i",$query) ) {