aboutsummaryrefslogtreecommitdiffstats
path: root/includes/Database.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/Database.php')
-rw-r--r--includes/Database.php55
1 files changed, 41 insertions, 14 deletions
diff --git a/includes/Database.php b/includes/Database.php
index b66e7178dc8c..724a6e98d8c4 100644
--- a/includes/Database.php
+++ b/includes/Database.php
@@ -37,7 +37,7 @@ class Database {
*/
var $mLastQuery = '';
- var $mServer, $mUser, $mPassword, $mConn, $mDBname;
+ var $mServer, $mUser, $mPassword, $mConn = null, $mDBname;
var $mOut, $mOpened = false;
var $mFailFunction;
@@ -215,7 +215,14 @@ class Database {
@/**/$this->mConn = mysql_pconnect( $server, $user, $password );
} else {
# Create a new connection...
- @/**/$this->mConn = mysql_connect( $server, $user, $password, true );
+ if( version_compare( PHP_VERSION, '4.2.0', 'ge' ) ) {
+ @/**/$this->mConn = mysql_connect( $server, $user, $password, true );
+ } else {
+ # On PHP 4.1 the new_link parameter is not available. We cannot
+ # guarantee that we'll actually get a new connection, and this
+ # may cause some operations to fail possibly.
+ @/**/$this->mConn = mysql_connect( $server, $user, $password );
+ }
}
if ( $dbName != '' ) {
@@ -237,8 +244,15 @@ class Database {
if ( !$success ) {
$this->reportConnectionError();
- $this->close();
}
+
+ global $wgDBmysql5;
+ if( $wgDBmysql5 ) {
+ // Tell the server we're communicating with it in UTF-8.
+ // This may engage various charset conversions.
+ $this->query( 'SET NAMES utf8' );
+ }
+
$this->mOpened = $success;
return $success;
}
@@ -266,16 +280,15 @@ class Database {
/**
* @access private
* @param string $msg error message ?
- * @todo parameter $msg is not used
*/
- function reportConnectionError( $msg = '') {
+ function reportConnectionError() {
if ( $this->mFailFunction ) {
if ( !is_int( $this->mFailFunction ) ) {
$ff = $this->mFailFunction;
$ff( $this, mysql_error() );
}
} else {
- wfEmergencyAbort( $this, mysql_error() );
+ wfEmergencyAbort( $this, $this->lastError() );
}
}
@@ -591,7 +604,13 @@ class Database {
*/
function lastError() {
if ( $this->mConn ) {
- $error = mysql_error( $this->mConn );
+ # Even if it's non-zero, it can still be invalid
+ wfSuppressWarnings();
+ $error = mysql_error( $this->mConn );
+ if ( !$error ) {
+ $error = mysql_error();
+ }
+ wfRestoreWarnings();
} else {
$error = mysql_error();
}
@@ -1120,7 +1139,10 @@ class Database {
* PostgreSQL doesn't have them and returns ""
*/
function useIndexClause( $index ) {
- return "FORCE INDEX ($index)";
+ global $wgDBmysql4;
+ return $wgDBmysql4
+ ? "FORCE INDEX ($index)"
+ : "USE INDEX ($index)";
}
/**
@@ -1458,7 +1480,7 @@ class Database {
/**
* @todo document
*/
- function resultObject( &$result ) {
+ function resultObject( $result ) {
if( empty( $result ) ) {
return NULL;
} else {
@@ -1606,13 +1628,12 @@ class ResultWrapper {
*/
function wfEmergencyAbort( &$conn, $error ) {
global $wgTitle, $wgUseFileCache, $title, $wgInputEncoding, $wgOutputEncoding;
- global $wgSitename, $wgServer;
-
+ global $wgSitename, $wgServer, $wgMessageCache, $wgLogo;
+
# I give up, Brion is right. Getting the message cache to work when there is no DB is tricky.
# Hard coding strings instead.
- $noconnect = 'Sorry! The wiki is experiencing some technical difficulties, and cannot contact the database server. <br />
-$1';
+ $noconnect = "<h1><img src='$wgLogo' style='float:left;margin-right:1em' alt=''>$wgSitename has a problem</h1><p><strong>Sorry! This site is experiencing technical difficulties.</strong></p><p>Try waiting a few minutes and reloading.</p><p><small>(Can't contact the database server: $1)</small></p>";
$mainpage = 'Main Page';
$searchdisabled = <<<EOT
<p style="margin: 1.5em 2em 1em">$wgSitename search is disabled for performance reasons. You can search via Google in the meantime.
@@ -1648,9 +1669,15 @@ border=\"0\" ALT=\"Google\"></A>
header( 'Cache-control: none' );
header( 'Pragma: nocache' );
}
+
+ # No database access
+ if ( is_object( $wgMessageCache ) ) {
+ $wgMessageCache->disable();
+ }
+
$msg = wfGetSiteNotice();
if($msg == '') {
- $msg = str_replace( '$1', $error, $noconnect );
+ $msg = str_replace( '$1', htmlspecialchars( $error ), $noconnect );
}
$text = $msg;