* @throws DBConnectionError
*/
function open( $server, $user, $password, $dbName ) {
- global $wgAllDBsAreLocalhost, $wgDBmysql5, $wgSQLMode;
+ global $wgAllDBsAreLocalhost, $wgSQLMode;
wfProfileIn( __METHOD__ );
# Debugging hack -- fake cluster
wfProfileOut( __METHOD__ );
- return $this->reportConnectionError( $error );
+ $this->reportConnectionError( $error );
}
if ( $dbName != '' ) {
wfProfileOut( __METHOD__ );
- return $this->reportConnectionError( "Error selecting database $dbName" );
+ $this->reportConnectionError( "Error selecting database $dbName" );
}
}
- // Tell the server we're communicating with it in UTF-8.
- // This may engage various charset conversions.
- if ( $wgDBmysql5 ) {
- $this->mysqlSetCharset( 'utf8' );
- } else {
- $this->mysqlSetCharset( 'binary' );
+ // Tell the server what we're communicating with
+ if ( !$this->connectInitCharset() ) {
+ $this->reportConnectionError( "Error setting character set" );
}
+
// Set SQL mode, default is turning them all off, can be overridden or skipped with null
if ( is_string( $wgSQLMode ) ) {
$mode = $this->addQuotes( $wgSQLMode );
if ( !$success ) {
wfLogDBError( "Error setting sql_mode to $mode on server {$this->mServer}" );
wfProfileOut( __METHOD__ );
- return $this->reportConnectionError( "Error setting sql_mode to $mode" );
+ $this->reportConnectionError( "Error setting sql_mode to $mode" );
}
}
return true;
}
+ /**
+ * Set the character set information right after connection
+ * @return bool
+ */
+ protected function connectInitCharset() {
+ global $wgDBmysql5;
+
+ if ( $wgDBmysql5 ) {
+ // Tell the server we're communicating with it in UTF-8.
+ // This may engage various charset conversions.
+ return $this->mysqlSetCharset( 'utf8' );
+ } else {
+ return $this->mysqlSetCharset( 'binary' );
+ }
+ }
+
/**
* Open a connection to a MySQL server
*
/**
* @param $res ResultWrapper
- * @param $n string
+ * @param $n int
* @return string
*/
function fieldName( $res, $n ) {
*/
abstract protected function mysqlFieldName( $res, $n );
+ /**
+ * mysql_field_type() wrapper
+ * @param $res
+ * @param $n int
+ * @return string
+ */
+ public function fieldType( $res, $n ) {
+ if ( $res instanceof ResultWrapper ) {
+ $res = $res->result;
+ }
+
+ return $this->mysqlFieldType( $res, $n );
+ }
+
+ /**
+ * Get the type of the specified field in a result
+ *
+ * @param $res Raw result
+ * @param $n int
+ * @return string
+ */
+ abstract protected function mysqlFieldType( $res, $n );
+
/**
* @param $res ResultWrapper
* @param $row