Index: src/wp-includes/drivers/class-wpdb-driver-mysql.php
===================================================================
--- src/wp-includes/drivers/class-wpdb-driver-mysql.php	(revision 0)
+++ src/wp-includes/drivers/class-wpdb-driver-mysql.php	(working copy)
@@ -0,0 +1,156 @@
+<?php
+
+/**
+ * Database driver, using the mysql extension.
+ *
+ * @link http://php.net/manual/en/book.mysqli.php
+ *
+ * @package WordPress
+ * @subpackage Database
+ * @since 3.8.0
+ */
+class wpdb_driver_mysql implements wpdb_driver {
+
+	/**
+	 * Database link
+	 * @var resource
+	 */
+	private $dbh = null;
+
+	/**
+	 * Result set
+	 * @var resource
+	 */
+	private $result = null;
+
+	/**
+	 * Cached column info
+	 * @var array|null
+	 */
+	private $col_info = null;
+
+	/**
+	 * Escape with mysql_real_escape_string()
+	 * @param  string $string
+	 * @return string
+	 */
+	public function escape( $string ) {
+		return mysql_real_escape_string( $string, $this->dbh );
+	}
+
+	/**
+	 * Get the latest error message from the DB driver
+	 * @return string
+	 */
+	public function get_error_message() {
+		return mysql_error( $this->dbh );
+	}
+
+	/**
+	 * Free memory associated with the resultset
+	 * @return void
+	 */
+	public function flush() {
+		if ( is_resource( $this->result ) )
+			mysql_free_result( $this->result );
+		$this->result = null;
+		$this->col_info = null;
+	}
+
+	/**
+	 * Connect to database
+	 * @return bool
+	 */
+	public function connect( $host, $user, $pass, $port = 3306, $options = array()  ) {
+		$new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true;
+		$client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0;
+
+		if ( WP_DEBUG ) {
+			$this->dbh =  mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags );
+		} else {
+			$this->dbh = @mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags );
+		}
+		return ( false !== $this->dbh );
+	}
+
+	/**
+	 * Select database
+	 * @return void
+	 */
+	public function select( $db ) {
+		if ( WP_DEBUG ) {
+			return mysql_select_db( $db, $this->dbh );
+		} else {
+			return @mysql_select_db( $db, $this->dbh );
+		}
+	}
+
+	/**
+	 * Perform a MySQL database query, using current database connection.
+	 * @param string $query Database query
+	 * @return int|false Number of rows affected/selected or false on error
+	 */
+	public function query( $query ) {
+		$return_val   = 0;
+		$this->result = @mysql_query( $query, $this->dbh );
+
+		if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) {
+			$return_val = $this->result;
+		} elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) {
+			$return_val = $this->affected_rows();
+		} elseif ( preg_match( '/^\s*select\s/i', $query ) ) {
+			return is_resource( $this->result ) ? mysql_num_rows( $this->result ) : false;
+		}
+
+		return $return_val;
+	}
+
+	/**
+	 * Get number of rows affected
+	 * @return int
+	 */
+	public function affected_rows() {
+		return mysql_affected_rows( $this->dbh );
+	}
+
+	/**
+	 * Get last insert id
+	 * @return int
+	 */
+	public function insert_id() {
+		return mysql_insert_id( $this->dbh );
+	}
+
+	/**
+	 * Get results
+	 * @return array
+	 */
+	public function get_results() {
+		$ret = array();
+		while ( $row = @mysql_fetch_object( $this->result ) ) {
+			$ret[] = $row;
+		}
+		return $ret;
+	}
+
+	/**
+	 * Load the column metadata from the last query.
+	 * @return array
+	 */
+	public function load_col_info() {
+		if ( $this->col_info )
+			return $this->col_info;
+		for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ )
+			$this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i );
+
+		return $this->col_info;
+	}
+
+	/**
+	 * The database version number.
+	 * @return false|string false on failure, version number on success
+	 */
+	public function db_version() {
+		return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) );
+	}
+}
\ No newline at end of file

Property changes on: src/wp-includes/drivers/class-wpdb-driver-mysql.php
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: src/wp-includes/drivers/class-wpdb-driver-mysqli.php
===================================================================
--- src/wp-includes/drivers/class-wpdb-driver-mysqli.php	(revision 0)
+++ src/wp-includes/drivers/class-wpdb-driver-mysqli.php	(working copy)
@@ -0,0 +1,160 @@
+<?php
+
+/**
+ * Database driver, using the mysqli extension.
+ *
+ * @link http://php.net/manual/en/book.mysqli.php
+ *
+ * @package WordPress
+ * @subpackage Database
+ * @since 3.8.0
+ */
+class wpdb_driver_mysqli implements wpdb_driver {
+
+	/**
+	 * Database link
+	 * @var mysqli
+	 */
+	private $dbh = null;
+
+	/**
+	 * Result set
+	 * @var mysqli_stmt|mysqli_result
+	 */
+	private $result = null;
+
+	/**
+	 * Cached column info
+	 * @var array|null
+	 */
+	private $col_info = null;
+
+	/**
+	 * Escape with mysql_real_escape_string()
+	 * @param  string $string
+	 * @return string
+	 */
+	public function escape( $string ) {
+		return $this->dbh->escape_string( $string );
+	}
+
+	/**
+	 * Get the latest error message from the DB driver
+	 * @return string
+	 */
+	public function get_error_message() {
+		return $this->dbh->error;
+	}
+
+	/**
+	 * Free memory associated with the resultset
+	 * @return void
+	 */
+	public function flush() {
+		if ( $this->result instanceof mysqli_stmt ) {
+			$this->result->free_result();
+		}
+		$this->result = null;
+		$this->col_info = null;
+	}
+
+	/**
+	 * Connect to database
+	 * @return bool
+	 */
+	public function connect( $host, $user, $pass, $port = 3306, $options = array() ) {
+		$this->dbh = new mysqli( $host, $user, $pass, '', $port );
+
+		if ( ! empty( $options['key'] ) && ! empty( $options['cert'] ) && ! empty( $options['ca'] ) ) {
+			$this->dbh->ssl_set(
+				$options['key'],
+				$options['cert'],
+				$options['ca'],
+				$options['ca_path'],
+				$options['cipher']
+			);
+		}
+
+		return ( ! mysqli_connect_error() );
+	}
+
+	/**
+	 * Select database
+	 * @return void
+	 */
+	public function select( $db ) {
+		return $this->dbh->select_db( $db );
+	}
+
+	/**
+	 * Perform a MySQL database query, using current database connection.
+	 * @param string $query Database query
+	 * @return int|false Number of rows affected/selected or false on error
+	 */
+	public function query( $query ) {
+		$return_val = 0;
+
+		$this->result = $this->dbh->query( $query );
+
+		if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) {
+			$return_val = $this->result;
+		} elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) {
+			$return_val = $this->affected_rows();
+		} elseif ( preg_match( '/^\s*select\s/i', $query ) ) {
+			return is_object( $this->result ) ? $this->result->num_rows : false;
+		}
+
+		return $return_val;
+	}
+
+	/**
+	 * Get number of rows affected
+	 * @return int
+	 */
+	public function affected_rows() {
+		return $this->dbh->affected_rows;
+	}
+
+	/**
+	 * Get last insert id
+	 * @return int
+	 */
+	public function insert_id() {
+		return $this->dbh->insert_id;
+	}
+
+	/**
+	 * Get results
+	 * @return array
+	 */
+	public function get_results() {
+		$ret = array();
+
+		if( is_object( $this->result ) ) {
+			while ( $row = $this->result->fetch_object() )
+				$ret[] = $row;
+		}
+
+		return $ret;
+	}
+
+	/**
+	 * Load the column metadata from the last query.
+	 * @return array
+	 */
+	public function load_col_info() {
+		if ( $this->col_info )
+			return $this->col_info;
+		for ( $i = 0; $i < $this->result->field_count ; $i++ )
+			$this->col_info[ $i ] = $this->result->fetch_field_direct( $i );
+		return $this->col_info;
+	}
+
+	/**
+	 * The database version number.
+	 * @return false|string false on failure, version number on success
+	 */
+	public function db_version() {
+		return preg_replace( '/[^0-9.].*/', '', $this->dbh->server_version );
+	}
+}

Property changes on: src/wp-includes/drivers/class-wpdb-driver-mysqli.php
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: src/wp-includes/drivers/class-wpdb-driver-pdo_mysql.php
===================================================================
--- src/wp-includes/drivers/class-wpdb-driver-pdo_mysql.php	(revision 0)
+++ src/wp-includes/drivers/class-wpdb-driver-pdo_mysql.php	(working copy)
@@ -0,0 +1,214 @@
+<?php
+
+/**
+ * Database driver, using the PDO extension.
+ *
+ * @link http://php.net/manual/en/book.pdo.php
+ *
+ * @package WordPress
+ * @subpackage Database
+ * @since 3.8.0
+ */
+class wpdb_driver_pdo_mysql implements wpdb_driver {
+
+	/**
+	 * Database link
+	 * @var PDO
+	 */
+	private $dbh = null;
+
+	/**
+	 * Result set
+	 * @var PDOStatement
+	 */
+	private $result = null;
+
+	/**
+	 * Cached column info
+	 * @var array|null
+	 */
+	private $col_info = null;
+
+	/**
+	 * Array of fetched rows.
+	 * PDO doesn't have a "count rows" feature, so we have to fetch the rows
+	 * up front, and cache them here
+	 * @var array
+	 */
+	private $fetched_rows = array();
+
+	/**
+	 * Escape with mysql_real_escape_string()
+	 * @param  string $string
+	 * @return string
+	 */
+	public function escape( $string ) {
+		return substr( $this->dbh->quote( $string ), 1, -1 );
+	}
+
+	/**
+	 * Get the latest error message from the DB driver
+	 * @return string
+	 */
+	public function get_error_message() {
+		$error = $this->dbh->errorInfo();
+		if ( isset( $error[2] ) ) {
+			return $error[2];
+		}
+		return '';
+	}
+
+	/**
+	 * Free memory associated with the resultset
+	 * @return void
+	 */
+	public function flush() {
+		if ( $this->result instanceof PDOStatement )
+			$this->result->closeCursor();
+		$this->result = null;
+		$this->col_info = null;
+		$this->fetched_rows = array();
+	}
+
+	/**
+	 * Connect to database
+	 * @return bool
+	 */
+	public function connect( $host, $user, $pass, $port = 3306, $options = array() ) {
+		$dsn = sprintf( 'mysql:host=%1$s;port=%2$d', $host, $port );
+
+		try {
+			$pdo_options = array();
+
+			if ( ! empty( $options['key'] ) && ! empty( $options['cert'] ) && ! empty( $options['ca'] ) ) {
+				$pdo_options[ PDO::MYSQL_ATTR_SSL_KEY ]    = $options['key'];
+				$pdo_options[ PDO::MYSQL_ATTR_SSL_CERT ]   = $options['cert'];
+				$pdo_options[ PDO::MYSQL_ATTR_SSL_CA ]     = $options['ca'];
+				$pdo_options[ PDO::MYSQL_ATTR_SSL_CAPATH ] = $options['ca_path'];
+				$pdo_options[ PDO::MYSQL_ATTR_SSL_CIPHER ] = $options['cipher'];
+
+				// Cleanup empty values
+				$pdo_options = array_filter( $pdo_options );
+			}
+
+			$this->dbh = new PDO( $dsn, $user, $pass, $pdo_options );
+			$this->dbh->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
+		} catch ( Exception $e ) {
+			return false;
+		}
+
+		return true;
+	}
+
+	/**
+	 * Select database
+	 * @return void
+	 */
+	public function select( $db ) {
+		try {
+			$this->dbh->exec( sprintf( 'USE `%s`', $db ) );
+		} catch ( Exception $e ) {
+			return false;
+		}
+
+		return true;
+	}
+
+	/**
+	 * Perform a MySQL database query, using current database connection.
+	 * @param string $query Database query
+	 * @return int|false Number of rows affected/selected or false on error
+	 */
+	public function query( $query ) {
+		$return_val = 0;
+
+		try {
+			$this->result = $this->dbh->query( $query );
+		} catch ( Exception $e ) {
+			if ( WP_DEBUG) {
+				global $wpdb;
+				error_log( "Error executing query: " . $e->getCode() . " - " . $e->getMessage() . " in query " . $query );
+			}
+			return false;
+		}
+
+		if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) {
+			$return_val = $this->result;
+		} elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) {
+			$return_val = $this->affected_rows();
+		} elseif ( preg_match( '/^\s*select\s/i', $query ) ) {
+			$this->get_results();
+			return count( $this->fetched_rows );
+		}
+
+		return $return_val;
+	}
+
+	/**
+	 * Get number of rows affected
+	 * @return int
+	 */
+	public function affected_rows() {
+		if ( $this->result instanceof PDOStatement )
+			return $this->result->rowCount();
+
+		return 0;
+	}
+
+	/**
+	 * Get last insert id
+	 * @return int
+	 */
+	public function insert_id() {
+		return $this->dbh->lastInsertId();
+	}
+
+	/**
+	 * Get results
+	 * @return array
+	 */
+	public function get_results() {
+		if ( !empty( $this->fetched_rows ) ) {
+			return $this->fetched_rows;
+		}
+		$this->fetched_rows = array();
+
+		if ( !empty( $this->result ) && $this->result->rowCount() > 0 ) {
+			try {
+				while ( $row = $this->result->fetchObject() )
+					$this->fetched_rows[] = $row;
+			} catch ( Exception $e ) {}
+		}
+
+		return $this->fetched_rows;
+	}
+
+	/**
+	 * Load the column metadata from the last query.
+	 * @return array
+	 */
+	public function load_col_info() {
+		if ( $this->col_info )
+			return $this->col_info;
+		for ( $i = 0; $i < $this->result->columnCount() ; $i++ ) {
+			$this->col_info[ $i ] = $this->result->fetchColumn( $i );
+		}
+		return $this->col_info;
+	}
+
+	/**
+	 * The database version number.
+	 * @return false|string false on failure, version number on success
+	 */
+	public function db_version() {
+		return preg_replace( '/[^0-9.].*/', '', $this->dbh->getAttribute( PDO::ATTR_SERVER_VERSION ) );
+	}
+
+	/**
+	 * Don't save any state.  The db wrapper should call connect() again.
+	 * @return array
+	 */
+	public function __sleep() {
+		return array();
+	}
+}
\ No newline at end of file

Property changes on: src/wp-includes/drivers/class-wpdb-driver-pdo_mysql.php
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: src/wp-includes/drivers/interface-wpdb-driver.php
===================================================================
--- src/wp-includes/drivers/interface-wpdb-driver.php	(revision 0)
+++ src/wp-includes/drivers/interface-wpdb-driver.php	(working copy)
@@ -0,0 +1,14 @@
+<?php
+interface wpdb_driver {
+	public function escape( $string );
+	public function get_error_message();
+	public function flush();
+	public function connect( $host, $user, $pass, $port = 3306, $options = array() );
+	public function select( $name );
+	public function query( $query );
+	public function load_col_info();
+	public function db_version();
+	public function affected_rows();
+	public function insert_id();
+	public function get_results();
+}
Index: src/wp-includes/wp-db.php
===================================================================
--- src/wp-includes/wp-db.php	(revision 26089)
+++ src/wp-includes/wp-db.php	(working copy)
@@ -9,6 +9,8 @@
  * @since 0.71
  */
 
+require_once( dirname( __FILE__ ) . '/drivers/interface-wpdb-driver.php' );
+
 /**
  * @since 0.71
  */
@@ -509,6 +511,42 @@
 	 */
 	public $is_mysql = null;
 
+ 	/**
+	 * Pick the adapter to be used for performing the actual queries.
+	 *
+	 * @since 3.8.0
+	 */
+	private function set_driver() {
+
+		// Auto-pick the driver
+		if ( defined( 'WPDB_DRIVER' ) ) {
+			$driver = WPDB_DRIVER;
+		} elseif ( extension_loaded( 'pdo_mysql' ) ) {
+			$driver = 'pdo_mysql';
+		} elseif ( extension_loaded( 'mysqli' ) ) {
+			$driver = 'mysqli';
+		} elseif ( extension_loaded( 'mysql' ) ) {
+			$driver = 'mysql';
+		}
+
+		// Get the new driver
+		if ( in_array( $driver, apply_filters( 'wpdb_drivers', array( 'mysql', 'mysqli', 'pdo_mysql' ) ) ) )
+			require_once( dirname( __FILE__ ) . '/drivers/class-wpdb-driver-' . $driver . '.php' );
+
+		$class = 'wpdb_driver_' . $driver;
+
+		if ( ! class_exists( $class ) ) {
+			wp_load_translations_early();
+			$this->bail( sprintf( __( "
+				<h1>No database drivers found</h1>.
+				<p>WordPress requires the mysql, mysqli, or pdo_mysql extension to talk to your database.</p>
+				<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>
+			"), 'db_connect_fail' ) );
+		}
+
+		$this->dbh = new $class();
+	}
+
 	/**
 	 * Connects to the database server and selects a database
 	 *
@@ -525,6 +563,8 @@
 	 * @param string $dbhost MySQL database host
 	 */
 	function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
+		$this->set_driver();
+
 		register_shutdown_function( array( $this, '__destruct' ) );
 
 		if ( WP_DEBUG && WP_DEBUG_DISPLAY )
@@ -636,15 +676,11 @@
 			$charset = $this->charset;
 		if ( ! isset( $collate ) )
 			$collate = $this->collate;
-		if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) {
-			if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
-				mysql_set_charset( $charset, $dbh );
-			} else {
-				$query = $this->prepare( 'SET NAMES %s', $charset );
-				if ( ! empty( $collate ) )
-					$query .= $this->prepare( ' COLLATE %s', $collate );
-				mysql_query( $query, $dbh );
-			}
+		if ( $this->has_cap( 'collation', $dbh ) && !empty( $charset ) ) {
+			$query = $this->prepare( 'SET NAMES %s', $charset );
+			if ( ! empty( $collate ) )
+				$query .= $this->prepare( ' COLLATE %s', $collate );
+			$this->dbh->query( $query );
 		}
 	}
 
@@ -827,10 +863,9 @@
 	 * @return null Always null.
 	 */
 	function select( $db, $dbh = null ) {
-		if ( is_null($dbh) )
-			$dbh = $this->dbh;
+		$result = $dbh->select( $db );
 
-		if ( !@mysql_select_db( $db, $dbh ) ) {
+		if ( ! $result ) {
 			$this->ready = false;
 			wp_load_translations_early();
 			$this->bail( sprintf( __( '<h1>Can&#8217;t select database</h1>
@@ -876,12 +911,7 @@
 	 * @return string escaped
 	 */
 	function _real_escape( $string ) {
-		if ( $this->dbh )
-			return mysql_real_escape_string( $string, $this->dbh );
-
-		$class = get_class( $this );
-		_doing_it_wrong( $class, "$class must set a database connection for use with escaping.", E_USER_NOTICE );
-		return addslashes( $string );
+		return $this->dbh->escape( $string );
 	}
 
 	/**
@@ -1019,7 +1049,7 @@
 		global $EZSQL_ERROR;
 
 		if ( !$str )
-			$str = mysql_error( $this->dbh );
+			$str = $this->dbh->get_error_message();
 		$EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str );
 
 		if ( $this->suppress_errors )
@@ -1116,14 +1146,13 @@
 	 * @return void
 	 */
 	function flush() {
+		$this->dbh->flush();
+
 		$this->last_result = array();
 		$this->col_info    = null;
 		$this->last_query  = null;
 		$this->rows_affected = $this->num_rows = 0;
 		$this->last_error  = '';
-
-		if ( is_resource( $this->result ) )
-			mysql_free_result( $this->result );
 	}
 
 	/**
@@ -1132,19 +1161,23 @@
 	 * @since 3.0.0
 	 */
 	function db_connect() {
-
 		$this->is_mysql = true;
 
-		$new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true;
-		$client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0;
-
-		if ( WP_DEBUG ) {
-			$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
-		} else {
-			$this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
+		if ( false !== strpos( $this->dbhost, ':' ) ) {
+			list( $host, $port ) = explode( ':', $this->dbhost );
+ 		} else {
+			$host = $this->dbhost;
+			$port = 3306;
 		}
 
-		if ( !$this->dbh ) {
+		$options = array();
+		$options['key'] = defined( 'DB_SSL_KEY' ) ? DB_SSL_KEY : null;
+		$options['cert'] = defined( 'DB_SSL_CERT' ) ? DB_SSL_CERT : null;
+		$options['ca'] = defined( 'DB_SSL_CA' ) ? DB_SSL_CA : null;
+		$options['ca_path'] = defined( 'DB_SSL_CA_PATH' ) ? DB_SSL_CA_PATH : null;
+		$options['cipher'] = defined( 'DB_SSL_CIPHER' ) ? DB_SSL_CIPHER : null;
+
+		if ( ! $this->dbh->connect( $host, $this->dbuser, $this->dbpassword, $port, $options ) ) {
 			wp_load_translations_early();
 			$this->bail( sprintf( __( "
 <h1>Error establishing a database connection</h1>
@@ -1180,14 +1213,8 @@
 	function query( $query ) {
 		if ( ! $this->ready )
 			return false;
-		/**
-		 * Filter the database query.
-		 *
-		 * Some queries are made before the plugins have been loaded, and thus cannot be filtered with this method.
-		 *
-		 * @since 2.1.0
-		 * @param string $query Database query.
-		 */
+
+		// some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
 		$query = apply_filters( 'query', $query );
 
 		$return_val = 0;
@@ -1202,18 +1229,14 @@
 		if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES )
 			$this->timer_start();
 
-		$this->result = @mysql_query( $query, $this->dbh );
+		$this->result = $this->dbh->query( $query );
 		$this->num_queries++;
 
 		if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES )
 			$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
 
 		// If there is an error then take note of it..
-		if ( $this->last_error = mysql_error( $this->dbh ) ) {
-			// Clear insert_id on a subsequent failed insert.
-			if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) )
-				$this->insert_id = 0;
-
+		if ( $this->last_error = $this->dbh->get_error_message() ) {
 			$this->print_error();
 			return false;
 		}
@@ -1221,26 +1244,19 @@
 		if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) {
 			$return_val = $this->result;
 		} elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) {
-			$this->rows_affected = mysql_affected_rows( $this->dbh );
+			$this->rows_affected = $this->dbh->affected_rows();
 			// Take note of the insert_id
 			if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) {
-				$this->insert_id = mysql_insert_id($this->dbh);
+				$this->insert_id = $this->dbh->insert_id();
 			}
 			// Return number of rows affected
 			$return_val = $this->rows_affected;
 		} else {
-			$num_rows = 0;
-			while ( $row = @mysql_fetch_object( $this->result ) ) {
-				$this->last_result[$num_rows] = $row;
-				$num_rows++;
-			}
-
-			// Log number of rows the query returned
-			// and return number of rows selected
-			$this->num_rows = $num_rows;
-			$return_val     = $num_rows;
+			$return_val = $this->num_rows = count( $this->result );
 		}
 
+		$this->last_result = $this->dbh->get_results();
+
 		return $return_val;
 	}
 
@@ -1571,12 +1587,7 @@
 	 * @access protected
 	 */
 	protected function load_col_info() {
-		if ( $this->col_info )
-			return;
-
-		for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) {
-			$this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i );
-		}
+		$this->col_info = $this->dbh->load_col_info();
 	}
 
 	/**
@@ -1747,6 +1758,6 @@
 	 * @return false|string false on failure, version number on success
 	 */
 	function db_version() {
-		return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) );
+		return $this->dbh->db_version();
 	}
 }
