diff --git wp-includes/class-wp-db-driver-mysql.php wp-includes/class-wp-db-driver-mysql.php
new file mode 100644
index 0000000..237a3b5
--- /dev/null
+++ wp-includes/class-wp-db-driver-mysql.php
@@ -0,0 +1,155 @@
+<?php
+
+/**
+ * Database driver, using the mysql extension.
+ *
+ * @link http://php.net/manual/en/book.mysqli.php
+ *
+ * @package WordPress
+ * @subpackage Database
+ * @since 3.6.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 ) {
+
+		$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 ) {
+			 mysql_select_db( $db, $this->dbh );
+		} else {
+			@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 ) {
+		$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 true;
+	}
+
+	/**
+	 * 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 ) );
+	}
+}
diff --git wp-includes/class-wp-db-driver-mysqli.php wp-includes/class-wp-db-driver-mysqli.php
new file mode 100644
index 0000000..fd3f681
--- /dev/null
+++ wp-includes/class-wp-db-driver-mysqli.php
@@ -0,0 +1,143 @@
+<?php
+
+/**
+ * Database driver, using the mysqli extension.
+ *
+ * @link http://php.net/manual/en/book.mysqli.php
+ *
+ * @package WordPress
+ * @subpackage Database
+ * @since 3.6.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 ) {
+		$this->dbh = new mysqli( $host, $user, $pass, '', $port );
+		return ( !mysqli_connect_error() );
+	}
+
+	/**
+	 * Select database
+	 * @return void
+	 */
+	public function select( $db ) {
+		$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 ) {
+		$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 $this->result->num_rows;
+		}
+		return true;
+	}
+
+	/**
+	 * 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();
+		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 );
+	}
+}
diff --git wp-includes/class-wp-db-driver-pdo_mysql.php wp-includes/class-wp-db-driver-pdo_mysql.php
new file mode 100644
index 0000000..6a2c47f
--- /dev/null
+++ wp-includes/class-wp-db-driver-pdo_mysql.php
@@ -0,0 +1,173 @@
+<?php
+
+/**
+ * Database driver, using the PDO extension.
+ *
+ * @link http://php.net/manual/en/book.pdo.php
+ *
+ * @package WordPress
+ * @subpackage Database
+ * @since 3.6.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 ) {
+		$dsn = sprintf( 'mysql:host=%1$s;port=%2$d', $host, $port );
+		try {
+			$this->dbh = new PDO( $dsn, $user, $pass );
+		} catch ( Exception $e ) {
+			return false;
+		}
+		return true;
+	}
+
+	/**
+	 * Select database
+	 * @return void
+	 */
+	public function select( $db ) {
+		$this->dbh->exec( sprintf( 'USE %s', $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 ) {
+		try {
+			$this->result = $this->dbh->query( $query );
+		} catch ( Exception $e ) {
+		}
+		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 true;
+	}
+
+	/**
+	 * 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 ) ) {
+			while ( $row = $this->result->fetchObject() ) {
+				$this->fetched_rows[] = $row;
+			}
+		}
+		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 ) );
+	}
+}
diff --git wp-includes/interface-wp-db-driver.php wp-includes/interface-wp-db-driver.php
new file mode 100644
index 0000000..8bb421a
--- /dev/null
+++ wp-includes/interface-wp-db-driver.php
@@ -0,0 +1,15 @@
+<?php
+
+interface wpdb_driver {
+	public function escape( $string );
+	public function get_error_message();
+	public function flush();
+	public function connect( $host, $user, $pass, $port = 3306 );
+	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();
+}
diff --git wp-includes/load.php wp-includes/load.php
index 1742af4..16e8b5e 100644
--- wp-includes/load.php
+++ wp-includes/load.php
@@ -326,6 +326,7 @@ function wp_set_lang_dir() {
 function require_wp_db() {
 	global $wpdb;
 
+	require( ABSPATH . WPINC . '/interface-wp-db-driver.php' );
 	require_once( ABSPATH . WPINC . '/wp-db.php' );
 	if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
 		require_once( WP_CONTENT_DIR . '/db.php' );
diff --git wp-includes/wp-db.php wp-includes/wp-db.php
index 391cfa4..de17d7b 100644
--- wp-includes/wp-db.php
+++ wp-includes/wp-db.php
@@ -487,11 +487,14 @@ class wpdb {
 	protected $dbhost;
 
 	/**
-	 * Database Handle
+	 * Database driver object
+	 *
+	 * Allow for simple, and backwards compatible, pluggable database drivers
+	 * like PDO_mysql and mysqli to power wpdb
 	 *
-	 * @since 0.71
 	 * @access protected
-	 * @var string
+	 * @since 3.5.0
+	 * @var wpdb_driver
 	 */
 	protected $dbh;
 
@@ -519,6 +522,42 @@ class wpdb {
 	public $is_mysql = null;
 
 	/**
+	 * Pick the adapter to be used for performing the actual queries.
+	 *
+	 * @since 3.6.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, array( 'mysql', 'mysqli', 'pdo_mysql' ) ) ) {
+			require_once( ABSPATH . WPINC . '/class-wp-db-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
 	 *
 	 * PHP5 style constructor for compatibility with PHP5. Does
@@ -534,6 +573,8 @@ class wpdb {
 	 * @param string $dbhost MySQL database host
 	 */
 	function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
+		$this->set_driver();
+
 		register_shutdown_function( array( $this, '__destruct' ) );
 
 		if ( WP_DEBUG )
@@ -646,15 +687,10 @@ class wpdb {
 		if ( !isset($collate) )
 			$collate = $this->collate;
 		if ( $this->has_cap( 'collation', $dbh ) && !empty( $charset ) ) {
-			if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset', $dbh ) ) {
-				mysql_set_charset( $charset, $dbh );
-				$this->real_escape = true;
-			} else {
-				$query = $this->prepare( 'SET NAMES %s', $charset );
-				if ( ! empty( $collate ) )
-					$query .= $this->prepare( ' COLLATE %s', $collate );
-				mysql_query( $query, $dbh );
-			}
+			$query = $this->prepare( 'SET NAMES %s', $charset );
+			if ( ! empty( $collate ) )
+				$query .= $this->prepare( ' COLLATE %s', $collate );
+			$this->dbh->query( $query );
 		}
 	}
 
@@ -837,22 +873,7 @@ class wpdb {
 	 * @return null Always null.
 	 */
 	function select( $db, $dbh = null ) {
-		if ( is_null($dbh) )
-			$dbh = $this->dbh;
-
-		if ( !@mysql_select_db( $db, $dbh ) ) {
-			$this->ready = false;
-			wp_load_translations_early();
-			$this->bail( sprintf( __( '<h1>Can&#8217;t select database</h1>
-<p>We were able to connect to the database server (which means your username and password is okay) but not able to select the <code>%1$s</code> database.</p>
-<ul>
-<li>Are you sure it exists?</li>
-<li>Does the user <code>%2$s</code> have permission to use the <code>%1$s</code> database?</li>
-<li>On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?</li>
-</ul>
-<p>If you don\'t know how to set up a database you should <strong>contact your host</strong>. If all else fails you may find help at the <a href="http://wordpress.org/support/">WordPress Support Forums</a>.</p>' ), htmlspecialchars( $db, ENT_QUOTES ), htmlspecialchars( $this->dbuser, ENT_QUOTES ) ), 'db_select_fail' );
-			return;
-		}
+		$this->dbh->select( $db );
 	}
 
 	/**
@@ -882,7 +903,7 @@ class wpdb {
 	 */
 	function _real_escape( $string ) {
 		if ( $this->dbh && $this->real_escape )
-			return mysql_real_escape_string( $string, $this->dbh );
+			return $this->dbh->escape( $string );
 		else
 			return addslashes( $string );
 	}
@@ -1017,7 +1038,7 @@ class wpdb {
 		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 )
@@ -1114,12 +1135,7 @@ class wpdb {
 	 * @return void
 	 */
 	function flush() {
-		$this->last_result = array();
-		$this->col_info    = null;
-		$this->last_query  = null;
-
-		if ( is_resource( $this->result ) )
-			mysql_free_result( $this->result );
+		$this->dbh->flush();
 	}
 
 	/**
@@ -1131,16 +1147,12 @@ class wpdb {
 
 		$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 );
+		$host = $this->dbhost;
+		$port = 3306;
+		if ( false !== strpos( $this->dbhost, ':' ) ) {
+			list( $host, $port ) = explode( ':', $this->dbhost );
 		}
-
-		if ( !$this->dbh ) {
+		if ( !$this->dbh->connect( $host, $this->dbuser, $this->dbpassword, $port ) ) {
 			wp_load_translations_early();
 			$this->bail( sprintf( __( "
 <h1>Error establishing a database connection</h1>
@@ -1192,14 +1204,14 @@ class wpdb {
 		if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES )
 			$this->timer_start();
 
-		$this->result = @mysql_query( $query, $this->dbh );
+		$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 ) ) {
+		if ( $this->last_error = $this->dbh->get_error_message() ) {
 			$this->print_error();
 			return false;
 		}
@@ -1207,26 +1219,18 @@ class wpdb {
 		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->last_result );
 		}
 
+		$this->last_result = $this->dbh->get_results();
 		return $return_val;
 	}
 
@@ -1556,12 +1560,7 @@ class wpdb {
 	 * @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();
 	}
 
 	/**
@@ -1732,6 +1731,6 @@ class wpdb {
 	 * @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();
 	}
 }
