Ticket #21663: 21663.7.patch
File 21663.7.patch, 81.6 KB (added by , 12 years ago) |
---|
-
new file wp-includes/class-wp-db-driver-mysql.php
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
- + 1 <?php 2 3 /** 4 * Database driver, using the mysql extension. 5 * 6 * @link http://php.net/manual/en/book.mysqli.php 7 * 8 * @package WordPress 9 * @subpackage Database 10 * @since 3.6.0 11 */ 12 class wpdb_driver_mysql implements wpdb_driver { 13 14 /** 15 * Database link 16 * @var resource 17 */ 18 private $dbh = null; 19 20 /** 21 * Result set 22 * @var resource 23 */ 24 private $result = null; 25 26 /** 27 * Cached column info 28 * @var array|null 29 */ 30 private $col_info = null; 31 32 /** 33 * Escape with mysql_real_escape_string() 34 * @param string $string 35 * @return string 36 */ 37 public function escape( $string ) { 38 return mysql_real_escape_string( $string, $this->dbh ); 39 } 40 41 /** 42 * Get the latest error message from the DB driver 43 * @return string 44 */ 45 public function get_error_message() { 46 return mysql_error( $this->dbh ); 47 } 48 49 /** 50 * Free memory associated with the resultset 51 * @return void 52 */ 53 public function flush() { 54 if ( is_resource( $this->result ) ) { 55 mysql_free_result( $this->result ); 56 } 57 $this->result = null; 58 $this->col_info = null; 59 } 60 61 /** 62 * Connect to database 63 * @return bool 64 */ 65 public function connect( $host, $user, $pass, $port = 3306 ) { 66 67 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; 68 $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; 69 70 if ( WP_DEBUG ) { 71 $this->dbh = mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 72 } else { 73 $this->dbh = @mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 74 } 75 return ( false !== $this->dbh ); 76 } 77 78 /** 79 * Select database 80 * @return void 81 */ 82 public function select( $db ) { 83 if ( WP_DEBUG ) { 84 mysql_select_db( $db, $this->dbh ); 85 } else { 86 @mysql_select_db( $db, $this->dbh ); 87 } 88 } 89 90 /** 91 * Perform a MySQL database query, using current database connection. 92 * @param string $query Database query 93 * @return int|false Number of rows affected/selected or false on error 94 */ 95 public function query( $query ) { 96 $this->result = @mysql_query( $query, $this->dbh ); 97 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 98 $return_val = $this->result; 99 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 100 $return_val = $this->affected_rows(); 101 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 102 return is_resource( $this->result ) ? mysql_num_rows( $this->result ) : false ; 103 } 104 return true; 105 } 106 107 /** 108 * Get number of rows affected 109 * @return int 110 */ 111 public function affected_rows() { 112 return mysql_affected_rows( $this->dbh ); 113 } 114 115 /** 116 * Get last insert id 117 * @return int 118 */ 119 public function insert_id() { 120 return mysql_insert_id( $this->dbh ); 121 } 122 123 /** 124 * Get results 125 * @return array 126 */ 127 public function get_results() { 128 $ret = array(); 129 while ( $row = @mysql_fetch_object( $this->result ) ) { 130 $ret[] = $row; 131 } 132 return $ret; 133 } 134 135 /** 136 * Load the column metadata from the last query. 137 * @return array 138 */ 139 public function load_col_info() { 140 if ( $this->col_info ) 141 return $this->col_info; 142 for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) { 143 $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); 144 } 145 return $this->col_info; 146 } 147 148 /** 149 * The database version number. 150 * @return false|string false on failure, version number on success 151 */ 152 public function db_version() { 153 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 154 } 155 } -
new file wp-includes/class-wp-db-driver-mysqli.php
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
- + 1 <?php 2 3 /** 4 * Database driver, using the mysqli extension. 5 * 6 * @link http://php.net/manual/en/book.mysqli.php 7 * 8 * @package WordPress 9 * @subpackage Database 10 * @since 3.6.0 11 */ 12 class wpdb_driver_mysqli implements wpdb_driver { 13 14 /** 15 * Database link 16 * @var mysqli 17 */ 18 private $dbh = null; 19 20 /** 21 * Result set 22 * @var mysqli_stmt|mysqli_result 23 */ 24 private $result = null; 25 26 /** 27 * Cached column info 28 * @var array|null 29 */ 30 private $col_info = null; 31 32 /** 33 * Escape with mysql_real_escape_string() 34 * @param string $string 35 * @return string 36 */ 37 public function escape( $string ) { 38 return $this->dbh->escape_string( $string ); 39 } 40 41 /** 42 * Get the latest error message from the DB driver 43 * @return string 44 */ 45 public function get_error_message() { 46 return $this->dbh->error; 47 } 48 49 /** 50 * Free memory associated with the resultset 51 * @return void 52 */ 53 public function flush() { 54 if ( $this->result instanceof mysqli_stmt ) { 55 $this->result->free_result(); 56 } 57 $this->result = null; 58 $this->col_info = null; 59 } 60 61 /** 62 * Connect to database 63 * @return bool 64 */ 65 public function connect( $host, $user, $pass, $port = 3306 ) { 66 $this->dbh = new mysqli( $host, $user, $pass, '', $port ); 67 return ( !mysqli_connect_error() ); 68 } 69 70 /** 71 * Select database 72 * @return void 73 */ 74 public function select( $db ) { 75 $this->dbh->select_db( $db ); 76 } 77 78 /** 79 * Perform a MySQL database query, using current database connection. 80 * @param string $query Database query 81 * @return int|false Number of rows affected/selected or false on error 82 */ 83 public function query( $query ) { 84 $this->result = $this->dbh->query( $query ); 85 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 86 $return_val = $this->result; 87 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 88 $return_val = $this->affected_rows(); 89 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 90 return $this->result->num_rows; 91 } 92 return true; 93 } 94 95 /** 96 * Get number of rows affected 97 * @return int 98 */ 99 public function affected_rows() { 100 return $this->dbh->affected_rows; 101 } 102 103 /** 104 * Get last insert id 105 * @return int 106 */ 107 public function insert_id() { 108 return $this->dbh->insert_id; 109 } 110 111 /** 112 * Get results 113 * @return array 114 */ 115 public function get_results() { 116 $ret = array(); 117 while ( $row = $this->result->fetch_object() ) { 118 $ret[] = $row; 119 } 120 return $ret; 121 } 122 123 /** 124 * Load the column metadata from the last query. 125 * @return array 126 */ 127 public function load_col_info() { 128 if ( $this->col_info ) 129 return $this->col_info; 130 for ( $i = 0; $i < $this->result->field_count ; $i++ ) { 131 $this->col_info[ $i ] = $this->result->fetch_field_direct( $i ); 132 } 133 return $this->col_info; 134 } 135 136 /** 137 * The database version number. 138 * @return false|string false on failure, version number on success 139 */ 140 public function db_version() { 141 return preg_replace( '/[^0-9.].*/', '', $this->dbh->server_version ); 142 } 143 } -
new file wp-includes/class-wp-db-driver-pdo_mysql.php
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
- + 1 <?php 2 3 /** 4 * Database driver, using the PDO extension. 5 * 6 * @link http://php.net/manual/en/book.pdo.php 7 * 8 * @package WordPress 9 * @subpackage Database 10 * @since 3.6.0 11 */ 12 class wpdb_driver_pdo_mysql implements wpdb_driver { 13 14 /** 15 * Database link 16 * @var PDO 17 */ 18 private $dbh = null; 19 20 /** 21 * Result set 22 * @var PDOStatement 23 */ 24 private $result = null; 25 26 /** 27 * Cached column info 28 * @var array|null 29 */ 30 private $col_info = null; 31 32 /** 33 * Array of fetched rows. 34 * PDO doesn't have a "count rows" feature, so we have to fetch the rows 35 * up front, and cache them here 36 * @var array 37 */ 38 private $fetched_rows = array(); 39 40 /** 41 * Escape with mysql_real_escape_string() 42 * @param string $string 43 * @return string 44 */ 45 public function escape( $string ) { 46 return substr( $this->dbh->quote( $string ), 1, -1 ); 47 } 48 49 /** 50 * Get the latest error message from the DB driver 51 * @return string 52 */ 53 public function get_error_message() { 54 $error = $this->dbh->errorInfo(); 55 if ( isset( $error[2] ) ) { 56 return $error[2]; 57 } 58 return ''; 59 } 60 61 /** 62 * Free memory associated with the resultset 63 * @return void 64 */ 65 public function flush() { 66 if ( $this->result instanceof PDOStatement ) { 67 $this->result->closeCursor(); 68 } 69 $this->result = null; 70 $this->col_info = null; 71 $this->fetched_rows = array(); 72 } 73 74 /** 75 * Connect to database 76 * @return bool 77 */ 78 public function connect( $host, $user, $pass, $port = 3306 ) { 79 $dsn = sprintf( 'mysql:host=%1$s;port=%2$d', $host, $port ); 80 try { 81 $this->dbh = new PDO( $dsn, $user, $pass ); 82 } catch ( Exception $e ) { 83 return false; 84 } 85 return true; 86 } 87 88 /** 89 * Select database 90 * @return void 91 */ 92 public function select( $db ) { 93 $this->dbh->exec( sprintf( 'USE %s', $db ) ); 94 } 95 96 /** 97 * Perform a MySQL database query, using current database connection. 98 * @param string $query Database query 99 * @return int|false Number of rows affected/selected or false on error 100 */ 101 public function query( $query ) { 102 try { 103 $this->result = $this->dbh->query( $query ); 104 } catch ( Exception $e ) { 105 } 106 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 107 $return_val = $this->result; 108 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 109 $return_val = $this->affected_rows(); 110 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 111 $this->get_results(); 112 return count( $this->fetched_rows ); 113 } 114 return true; 115 } 116 117 /** 118 * Get number of rows affected 119 * @return int 120 */ 121 public function affected_rows() { 122 if ( $this->result instanceof PDOStatement ) { 123 return $this->result->rowCount(); 124 } 125 return 0; 126 } 127 128 /** 129 * Get last insert id 130 * @return int 131 */ 132 public function insert_id() { 133 return $this->dbh->lastInsertId(); 134 } 135 136 /** 137 * Get results 138 * @return array 139 */ 140 public function get_results() { 141 if ( !empty( $this->fetched_rows ) ) { 142 return $this->fetched_rows; 143 } 144 $this->fetched_rows = array(); 145 if ( !empty( $this->result ) ) { 146 while ( $row = $this->result->fetchObject() ) { 147 $this->fetched_rows[] = $row; 148 } 149 } 150 return $this->fetched_rows; 151 } 152 153 /** 154 * Load the column metadata from the last query. 155 * @return array 156 */ 157 public function load_col_info() { 158 if ( $this->col_info ) 159 return $this->col_info; 160 for ( $i = 0; $i < $this->result->columnCount() ; $i++ ) { 161 $this->col_info[ $i ] = $this->result->fetchColumn( $i ); 162 } 163 return $this->col_info; 164 } 165 166 /** 167 * The database version number. 168 * @return false|string false on failure, version number on success 169 */ 170 public function db_version() { 171 return preg_replace( '/[^0-9.].*/', '', $this->dbh->getAttribute( PDO::ATTR_SERVER_VERSION ) ); 172 } 173 } -
new file wp-includes/class.wp-db-driver-mysql.php
diff --git wp-includes/class.wp-db-driver-mysql.php wp-includes/class.wp-db-driver-mysql.php new file mode 100644 index 0000000..baef192
- + 1 <?php 2 3 /** 4 * WordPress Database Access Abstraction Object 5 * 6 * It is possible to replace this class with your own 7 * by setting the $wpdb global variable in wp-content/db.php 8 * file to your class. The wpdb class will still be included, 9 * so you can extend it or simply use your own. 10 * 11 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 12 * 13 * @package WordPress 14 * @subpackage Database 15 * @since 0.71 16 */ 17 class wpdb_driver_mysql implements wpdb_driver { 18 19 /** 20 * Database link 21 * @var resource 22 */ 23 private $dbh = null; 24 25 /** 26 * Result set 27 * @var resource 28 */ 29 private $result = null; 30 31 /** 32 * Cached column info 33 * @var array|null 34 */ 35 private $col_info = null; 36 37 /** 38 * Escape with mysql_real_escape_string() 39 * @param string $string 40 * @return string 41 */ 42 public function escape( $string ) { 43 return mysql_real_escape_string( $string, $this->dbh ); 44 } 45 46 /** 47 * Get the latest error message from the DB driver 48 * @return string 49 */ 50 public function get_error_message() { 51 return mysql_error( $this->dbh ); 52 } 53 54 /** 55 * Free memory associated with the resultset 56 * @return void 57 */ 58 public function flush() { 59 if ( is_resource( $this->result ) ) { 60 mysql_free_result( $this->result ); 61 } 62 $this->result = null; 63 $this->col_info = null; 64 } 65 66 /** 67 * Connect to database 68 * @return bool 69 */ 70 public function connect( $host, $user, $pass, $port = 3306 ) { 71 72 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; 73 $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; 74 75 if ( WP_DEBUG ) { 76 $this->dbh = mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 77 } else { 78 $this->dbh = @mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 79 } 80 return ( false !== $this->dbh ); 81 } 82 83 /** 84 * Select database 85 * @return void 86 */ 87 public function select( $db ) { 88 if ( WP_DEBUG ) { 89 mysql_select_db( $db, $this->dbh ); 90 } else { 91 @mysql_select_db( $db, $this->dbh ); 92 } 93 } 94 95 /** 96 * Perform a MySQL database query, using current database connection. 97 * @param string $query Database query 98 * @return int|false Number of rows affected/selected or false on error 99 */ 100 public function query( $query ) { 101 $this->result = @mysql_query( $query, $this->dbh ); 102 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 103 $return_val = $this->result; 104 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 105 $return_val = $this->affected_rows(); 106 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 107 return is_resource( $this->result ) ? mysql_num_rows( $this->result ) : false ; 108 } 109 return true; 110 } 111 112 /** 113 * Get number of rows affected 114 * @return int 115 */ 116 public function affected_rows() { 117 return mysql_affected_rows( $this->dbh ); 118 } 119 120 /** 121 * Get last insert id 122 * @return int 123 */ 124 public function insert_id() { 125 return mysql_insert_id( $this->dbh ); 126 } 127 128 /** 129 * Get results 130 * @return array 131 */ 132 public function get_results() { 133 $ret = array(); 134 while ( $row = @mysql_fetch_object( $this->result ) ) { 135 $ret[] = $row; 136 } 137 return $ret; 138 } 139 140 /** 141 * Load the column metadata from the last query. 142 * @return array 143 */ 144 public function load_col_info() { 145 if ( $this->col_info ) 146 return $this->col_info; 147 for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) { 148 $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); 149 } 150 return $this->col_info; 151 } 152 153 /** 154 * The database version number. 155 * @return false|string false on failure, version number on success 156 */ 157 public function db_version() { 158 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 159 } 160 } 161 <?php 162 163 /** 164 * WordPress Database Access Abstraction Object 165 * 166 * It is possible to replace this class with your own 167 * by setting the $wpdb global variable in wp-content/db.php 168 * file to your class. The wpdb class will still be included, 169 * so you can extend it or simply use your own. 170 * 171 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 172 * 173 * @package WordPress 174 * @subpackage Database 175 * @since 0.71 176 */ 177 class wpdb_driver_mysql implements wpdb_driver { 178 179 /** 180 * Database link 181 * @var resource 182 */ 183 private $dbh = null; 184 185 /** 186 * Result set 187 * @var resource 188 */ 189 private $result = null; 190 191 /** 192 * Cached column info 193 * @var array|null 194 */ 195 private $col_info = null; 196 197 /** 198 * Escape with mysql_real_escape_string() 199 * @param string $string 200 * @return string 201 */ 202 public function escape( $string ) { 203 return mysql_real_escape_string( $string, $this->dbh ); 204 } 205 206 /** 207 * Get the latest error message from the DB driver 208 * @return string 209 */ 210 public function get_error_message() { 211 return mysql_error( $this->dbh ); 212 } 213 214 /** 215 * Free memory associated with the resultset 216 * @return void 217 */ 218 public function flush() { 219 if ( is_resource( $this->result ) ) { 220 mysql_free_result( $this->result ); 221 } 222 $this->result = null; 223 $this->col_info = null; 224 } 225 226 /** 227 * Connect to database 228 * @return bool 229 */ 230 public function connect( $host, $user, $pass, $port = 3306 ) { 231 232 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; 233 $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; 234 235 if ( WP_DEBUG ) { 236 $this->dbh = mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 237 } else { 238 $this->dbh = @mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 239 } 240 return ( false !== $this->dbh ); 241 } 242 243 /** 244 * Select database 245 * @return void 246 */ 247 public function select( $db ) { 248 if ( WP_DEBUG ) { 249 mysql_select_db( $db, $this->dbh ); 250 } else { 251 @mysql_select_db( $db, $this->dbh ); 252 } 253 } 254 255 /** 256 * Perform a MySQL database query, using current database connection. 257 * @param string $query Database query 258 * @return int|false Number of rows affected/selected or false on error 259 */ 260 public function query( $query ) { 261 $this->result = @mysql_query( $query, $this->dbh ); 262 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 263 $return_val = $this->result; 264 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 265 $return_val = $this->affected_rows(); 266 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 267 return is_resource( $this->result ) ? mysql_num_rows( $this->result ) : false ; 268 } 269 return true; 270 } 271 272 /** 273 * Get number of rows affected 274 * @return int 275 */ 276 public function affected_rows() { 277 return mysql_affected_rows( $this->dbh ); 278 } 279 280 /** 281 * Get last insert id 282 * @return int 283 */ 284 public function insert_id() { 285 return mysql_insert_id( $this->dbh ); 286 } 287 288 /** 289 * Get results 290 * @return array 291 */ 292 public function get_results() { 293 $ret = array(); 294 while ( $row = @mysql_fetch_object( $this->result ) ) { 295 $ret[] = $row; 296 } 297 return $ret; 298 } 299 300 /** 301 * Load the column metadata from the last query. 302 * @return array 303 */ 304 public function load_col_info() { 305 if ( $this->col_info ) 306 return $this->col_info; 307 for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) { 308 $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); 309 } 310 return $this->col_info; 311 } 312 313 /** 314 * The database version number. 315 * @return false|string false on failure, version number on success 316 */ 317 public function db_version() { 318 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 319 } 320 } 321 No newline at end of file -
new file wp-includes/class.wp-db-driver-mysqli.php
diff --git wp-includes/class.wp-db-driver-mysqli.php wp-includes/class.wp-db-driver-mysqli.php new file mode 100644 index 0000000..a7bef7d
- + 1 <?php 2 3 /** 4 * WordPress Database Access Abstraction Object 5 * 6 * It is possible to replace this class with your own 7 * by setting the $wpdb global variable in wp-content/db.php 8 * file to your class. The wpdb class will still be included, 9 * so you can extend it or simply use your own. 10 * 11 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 12 * 13 * @package WordPress 14 * @subpackage Database 15 * @since 0.71 16 */ 17 class wpdb_driver_mysqli implements wpdb_driver { 18 19 /** 20 * Database link 21 * @var mysqli 22 */ 23 private $dbh = null; 24 25 /** 26 * Result set 27 * @var mysqli_stmt|mysqli_result 28 */ 29 private $result = null; 30 31 /** 32 * Cached column info 33 * @var array|null 34 */ 35 private $col_info = null; 36 37 /** 38 * Escape with mysql_real_escape_string() 39 * @param string $string 40 * @return string 41 */ 42 public function escape( $string ) { 43 return $this->dbh->escape_string( $string ); 44 } 45 46 /** 47 * Get the latest error message from the DB driver 48 * @return string 49 */ 50 public function get_error_message() { 51 return $this->dbh->error; 52 } 53 54 /** 55 * Free memory associated with the resultset 56 * @return void 57 */ 58 public function flush() { 59 if ( $this->result instanceof mysqli_stmt ) { 60 $this->result->free_result(); 61 } 62 $this->result = null; 63 $this->col_info = null; 64 } 65 66 /** 67 * Connect to database 68 * @return bool 69 */ 70 public function connect( $host, $user, $pass, $port = 3306 ) { 71 $this->dbh = new mysqli( $host, $user, $pass, '', $port ); 72 return ( !mysqli_connect_error() ); 73 } 74 75 /** 76 * Select database 77 * @return void 78 */ 79 public function select( $db ) { 80 $this->dbh->select_db( $db ); 81 } 82 83 /** 84 * Perform a MySQL database query, using current database connection. 85 * @param string $query Database query 86 * @return int|false Number of rows affected/selected or false on error 87 */ 88 public function query( $query ) { 89 $this->result = $this->dbh->query( $query ); 90 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 91 $return_val = $this->result; 92 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 93 $return_val = $this->affected_rows(); 94 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 95 return $this->result->num_rows; 96 } 97 return true; 98 } 99 100 /** 101 * Get number of rows affected 102 * @return int 103 */ 104 public function affected_rows() { 105 return $this->dbh->affected_rows; 106 } 107 108 /** 109 * Get last insert id 110 * @return int 111 */ 112 public function insert_id() { 113 return $this->dbh->insert_id; 114 } 115 116 /** 117 * Get results 118 * @return array 119 */ 120 public function get_results() { 121 $ret = array(); 122 while ( $row = $this->result->fetch_object() ) { 123 $ret[] = $row; 124 } 125 return $ret; 126 } 127 128 /** 129 * Load the column metadata from the last query. 130 * @return array 131 */ 132 public function load_col_info() { 133 if ( $this->col_info ) 134 return $this->col_info; 135 for ( $i = 0; $i < $this->result->field_count ; $i++ ) { 136 $this->col_info[ $i ] = $this->result->fetch_field_direct( $i ); 137 } 138 return $this->col_info; 139 } 140 141 /** 142 * The database version number. 143 * @return false|string false on failure, version number on success 144 */ 145 public function db_version() { 146 return preg_replace( '/[^0-9.].*/', '', $this->dbh->server_version ); 147 } 148 } 149 <?php 150 151 /** 152 * WordPress Database Access Abstraction Object 153 * 154 * It is possible to replace this class with your own 155 * by setting the $wpdb global variable in wp-content/db.php 156 * file to your class. The wpdb class will still be included, 157 * so you can extend it or simply use your own. 158 * 159 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 160 * 161 * @package WordPress 162 * @subpackage Database 163 * @since 0.71 164 */ 165 class wpdb_driver_mysqli implements wpdb_driver { 166 167 /** 168 * Database link 169 * @var mysqli 170 */ 171 private $dbh = null; 172 173 /** 174 * Result set 175 * @var mysqli_stmt|mysqli_result 176 */ 177 private $result = null; 178 179 /** 180 * Cached column info 181 * @var array|null 182 */ 183 private $col_info = null; 184 185 /** 186 * Escape with mysql_real_escape_string() 187 * @param string $string 188 * @return string 189 */ 190 public function escape( $string ) { 191 return $this->dbh->escape_string( $string ); 192 } 193 194 /** 195 * Get the latest error message from the DB driver 196 * @return string 197 */ 198 public function get_error_message() { 199 return $this->dbh->error; 200 } 201 202 /** 203 * Free memory associated with the resultset 204 * @return void 205 */ 206 public function flush() { 207 if ( $this->result instanceof mysqli_stmt ) { 208 $this->result->free_result(); 209 } 210 $this->result = null; 211 $this->col_info = null; 212 } 213 214 /** 215 * Connect to database 216 * @return bool 217 */ 218 public function connect( $host, $user, $pass, $port = 3306 ) { 219 $this->dbh = new mysqli( $host, $user, $pass, '', $port ); 220 return ( !mysqli_connect_error() ); 221 } 222 223 /** 224 * Select database 225 * @return void 226 */ 227 public function select( $db ) { 228 $this->dbh->select_db( $db ); 229 } 230 231 /** 232 * Perform a MySQL database query, using current database connection. 233 * @param string $query Database query 234 * @return int|false Number of rows affected/selected or false on error 235 */ 236 public function query( $query ) { 237 $this->result = $this->dbh->query( $query ); 238 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 239 $return_val = $this->result; 240 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 241 $return_val = $this->affected_rows(); 242 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 243 return $this->result->num_rows; 244 } 245 return true; 246 } 247 248 /** 249 * Get number of rows affected 250 * @return int 251 */ 252 public function affected_rows() { 253 return $this->dbh->affected_rows; 254 } 255 256 /** 257 * Get last insert id 258 * @return int 259 */ 260 public function insert_id() { 261 return $this->dbh->insert_id; 262 } 263 264 /** 265 * Get results 266 * @return array 267 */ 268 public function get_results() { 269 $ret = array(); 270 while ( $row = $this->result->fetch_object() ) { 271 $ret[] = $row; 272 } 273 return $ret; 274 } 275 276 /** 277 * Load the column metadata from the last query. 278 * @return array 279 */ 280 public function load_col_info() { 281 if ( $this->col_info ) 282 return $this->col_info; 283 for ( $i = 0; $i < $this->result->field_count ; $i++ ) { 284 $this->col_info[ $i ] = $this->result->fetch_field_direct( $i ); 285 } 286 return $this->col_info; 287 } 288 289 /** 290 * The database version number. 291 * @return false|string false on failure, version number on success 292 */ 293 public function db_version() { 294 return preg_replace( '/[^0-9.].*/', '', $this->dbh->server_version ); 295 } 296 } 297 No newline at end of file -
new file wp-includes/class.wp-db-driver-pdo_mysql.php
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..72fc717
- + 1 <?php 2 3 /** 4 * WordPress Database Access Abstraction Object 5 * 6 * It is possible to replace this class with your own 7 * by setting the $wpdb global variable in wp-content/db.php 8 * file to your class. The wpdb class will still be included, 9 * so you can extend it or simply use your own. 10 * 11 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 12 * 13 * @package WordPress 14 * @subpackage Database 15 * @since 0.71 16 */ 17 class wpdb_driver_pdo_mysql implements wpdb_driver { 18 19 /** 20 * Database link 21 * @var PDO 22 */ 23 private $dbh = null; 24 25 /** 26 * Result set 27 * @var PDOStatement 28 */ 29 private $result = null; 30 31 /** 32 * Cached column info 33 * @var array|null 34 */ 35 private $col_info = null; 36 37 /** 38 * Array of fetched rows. 39 * PDO doesn't have a "count rows" feature, so we have to fetch the rows 40 * up front, and cache them here 41 * @var array 42 */ 43 private $fetched_rows = array(); 44 45 /** 46 * Escape with mysql_real_escape_string() 47 * @param string $string 48 * @return string 49 */ 50 public function escape( $string ) { 51 return substr( $this->dbh->quote( $string ), 1, -1 ); 52 } 53 54 /** 55 * Get the latest error message from the DB driver 56 * @return string 57 */ 58 public function get_error_message() { 59 $error = $this->dbh->errorInfo(); 60 if ( isset( $error[2] ) ) { 61 return $error[2]; 62 } 63 return ''; 64 } 65 66 /** 67 * Free memory associated with the resultset 68 * @return void 69 */ 70 public function flush() { 71 if ( $this->result instanceof PDOStatement ) { 72 $this->result->closeCursor(); 73 } 74 $this->result = null; 75 $this->col_info = null; 76 $this->fetched_rows = array(); 77 } 78 79 /** 80 * Connect to database 81 * @return bool 82 */ 83 public function connect( $host, $user, $pass, $port = 3306 ) { 84 $dsn = sprintf( 'mysql:host=%1$s;port=%2$d', $host, $port ); 85 try { 86 $this->dbh = new PDO( $dsn, $user, $pass ); 87 } catch ( Exception $e ) { 88 return false; 89 } 90 return true; 91 } 92 93 /** 94 * Select database 95 * @return void 96 */ 97 public function select( $db ) { 98 $this->dbh->exec( sprintf( 'USE %s', $db ) ); 99 } 100 101 /** 102 * Perform a MySQL database query, using current database connection. 103 * @param string $query Database query 104 * @return int|false Number of rows affected/selected or false on error 105 */ 106 public function query( $query ) { 107 try { 108 $this->result = $this->dbh->query( $query ); 109 } catch ( Exception $e ) { 110 } 111 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 112 $return_val = $this->result; 113 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 114 $return_val = $this->affected_rows(); 115 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 116 $this->get_results(); 117 return count( $this->fetched_rows ); 118 } 119 return true; 120 } 121 122 /** 123 * Get number of rows affected 124 * @return int 125 */ 126 public function affected_rows() { 127 if ( $this->result instanceof PDOStatement ) { 128 return $this->result->rowCount(); 129 } 130 return 0; 131 } 132 133 /** 134 * Get last insert id 135 * @return int 136 */ 137 public function insert_id() { 138 return $this->dbh->lastInsertId(); 139 } 140 141 /** 142 * Get results 143 * @return array 144 */ 145 public function get_results() { 146 if ( !empty( $this->fetched_rows ) ) { 147 return $this->fetched_rows; 148 } 149 $this->fetched_rows = array(); 150 if ( !empty( $this->result ) ) { 151 while ( $row = $this->result->fetchObject() ) { 152 $this->fetched_rows[] = $row; 153 } 154 } 155 return $this->fetched_rows; 156 } 157 158 /** 159 * Load the column metadata from the last query. 160 * @return array 161 */ 162 public function load_col_info() { 163 if ( $this->col_info ) 164 return $this->col_info; 165 for ( $i = 0; $i < $this->result->columnCount() ; $i++ ) { 166 $this->col_info[ $i ] = $this->result->fetchColumn( $i ); 167 } 168 return $this->col_info; 169 } 170 171 /** 172 * The database version number. 173 * @return false|string false on failure, version number on success 174 */ 175 public function db_version() { 176 return preg_replace( '/[^0-9.].*/', '', $this->dbh->getAttribute( PDO::ATTR_SERVER_VERSION ) ); 177 } 178 } 179 <?php 180 181 /** 182 * WordPress Database Access Abstraction Object 183 * 184 * It is possible to replace this class with your own 185 * by setting the $wpdb global variable in wp-content/db.php 186 * file to your class. The wpdb class will still be included, 187 * so you can extend it or simply use your own. 188 * 189 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 190 * 191 * @package WordPress 192 * @subpackage Database 193 * @since 0.71 194 */ 195 class wpdb_driver_pdo_mysql implements wpdb_driver { 196 197 /** 198 * Database link 199 * @var PDO 200 */ 201 private $dbh = null; 202 203 /** 204 * Result set 205 * @var PDOStatement 206 */ 207 private $result = null; 208 209 /** 210 * Cached column info 211 * @var array|null 212 */ 213 private $col_info = null; 214 215 /** 216 * Array of fetched rows. 217 * PDO doesn't have a "count rows" feature, so we have to fetch the rows 218 * up front, and cache them here 219 * @var array 220 */ 221 private $fetched_rows = array(); 222 223 /** 224 * Escape with mysql_real_escape_string() 225 * @param string $string 226 * @return string 227 */ 228 public function escape( $string ) { 229 return substr( $this->dbh->quote( $string ), 1, -1 ); 230 } 231 232 /** 233 * Get the latest error message from the DB driver 234 * @return string 235 */ 236 public function get_error_message() { 237 $error = $this->dbh->errorInfo(); 238 return $error[2]; 239 } 240 241 /** 242 * Free memory associated with the resultset 243 * @return void 244 */ 245 public function flush() { 246 if ( $this->result instanceof PDOStatement ) { 247 $this->result->closeCursor(); 248 } 249 $this->result = null; 250 $this->col_info = null; 251 $this->fetched_rows = array(); 252 } 253 254 /** 255 * Connect to database 256 * @return bool 257 */ 258 public function connect( $host, $user, $pass, $port = 3306 ) { 259 $dsn = sprintf( 'mysql:host=%1$s;port=%2$d', $host, $port ); 260 try { 261 $this->dbh = new PDO( $dsn, $user, $pass ); 262 } catch ( Exception $e ) { 263 return false; 264 } 265 return true; 266 } 267 268 /** 269 * Select database 270 * @return void 271 */ 272 public function select( $db ) { 273 $this->dbh->exec( sprintf( 'USE %s', $db ) ); 274 } 275 276 /** 277 * Perform a MySQL database query, using current database connection. 278 * @param string $query Database query 279 * @return int|false Number of rows affected/selected or false on error 280 */ 281 public function query( $query ) { 282 try { 283 $this->result = $this->dbh->query( $query ); 284 } catch ( Exception $e ) { 285 } 286 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 287 $return_val = $this->result; 288 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 289 $return_val = $this->affected_rows(); 290 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 291 $this->get_results(); 292 return count( $this->fetched_rows ); 293 } 294 return true; 295 } 296 297 /** 298 * Get number of rows affected 299 * @return int 300 */ 301 public function affected_rows() { 302 if ( $this->result instanceof PDOStatement ) { 303 return $this->result->rowCount(); 304 } 305 return 0; 306 } 307 308 /** 309 * Get last insert id 310 * @return int 311 */ 312 public function insert_id() { 313 return $this->dbh->lastInsertId(); 314 } 315 316 /** 317 * Get results 318 * @return array 319 */ 320 public function get_results() { 321 if ( !empty( $this->fetched_rows ) ) { 322 return $this->fetched_rows; 323 } 324 $this->fetched_rows = array(); 325 if ( !empty( $this->result ) ) { 326 while ( $row = $this->result->fetchObject() ) { 327 $this->fetched_rows[] = $row; 328 } 329 } 330 return $this->fetched_rows; 331 } 332 333 /** 334 * Load the column metadata from the last query. 335 * @return array 336 */ 337 public function load_col_info() { 338 if ( $this->col_info ) 339 return $this->col_info; 340 for ( $i = 0; $i < $this->result->columnCount() ; $i++ ) { 341 $this->col_info[ $i ] = $this->result->fetchColumn( $i ); 342 } 343 return $this->col_info; 344 } 345 346 /** 347 * The database version number. 348 * @return false|string false on failure, version number on success 349 */ 350 public function db_version() { 351 return preg_replace( '/[^0-9.].*/', '', $this->dbh->getAttribute( PDO::ATTR_SERVER_VERSION ) ); 352 } 353 } 354 No newline at end of file -
new file wp-includes/class.wp-db-driver.interface.php
diff --git wp-includes/class.wp-db-driver.interface.php wp-includes/class.wp-db-driver.interface.php new file mode 100644 index 0000000..f0b9199
- + 1 <?php 2 3 interface wpdb_driver { 4 public function escape( $string ); 5 public function get_error_message(); 6 public function flush(); 7 public function connect( $host, $user, $pass, $port = 3306 ); 8 public function select( $name ); 9 public function query( $query ); 10 public function load_col_info(); 11 public function db_version(); 12 public function affected_rows(); 13 public function insert_id(); 14 public function get_results(); 15 } 16 <?php 17 18 interface wpdb_driver { 19 public function escape( $string ); 20 public function get_error_message(); 21 public function flush(); 22 public function connect( $host, $user, $pass, $port = 3306 ); 23 public function select( $name ); 24 public function query( $query ); 25 public function load_col_info(); 26 public function db_version(); 27 public function affected_rows(); 28 public function insert_id(); 29 public function get_results(); 30 } -
new file wp-includes/interface-wp-db-driver.php
diff --git wp-includes/interface-wp-db-driver.php wp-includes/interface-wp-db-driver.php new file mode 100644 index 0000000..8bb421a
- + 1 <?php 2 3 interface wpdb_driver { 4 public function escape( $string ); 5 public function get_error_message(); 6 public function flush(); 7 public function connect( $host, $user, $pass, $port = 3306 ); 8 public function select( $name ); 9 public function query( $query ); 10 public function load_col_info(); 11 public function db_version(); 12 public function affected_rows(); 13 public function insert_id(); 14 public function get_results(); 15 } -
wp-includes/load.php
diff --git wp-includes/load.php wp-includes/load.php index 8a94962..552d579 100644
function wp_check_php_mysql_versions() { 108 108 die( sprintf( __( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.' ), $php_version, $wp_version, $required_php_version ) ); 109 109 } 110 110 111 if ( ! extension_loaded( 'mysql' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {111 if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded ( 'pdo_mysql' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) { 112 112 wp_load_translations_early(); 113 113 die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) ); 114 114 } … … function wp_set_lang_dir() { 326 326 function require_wp_db() { 327 327 global $wpdb; 328 328 329 require( ABSPATH . WPINC . '/interface-wp-db-driver.php' ); 329 330 require_once( ABSPATH . WPINC . '/wp-db.php' ); 330 331 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) 331 332 require_once( WP_CONTENT_DIR . '/db.php' ); -
new file wp-includes/wp-db-driver-mysql.php
diff --git wp-includes/wp-db-driver-mysql.php wp-includes/wp-db-driver-mysql.php new file mode 100644 index 0000000..b89fe8f
- + 1 <?php 2 3 /** 4 * WordPress Database Access Abstraction Object 5 * 6 * It is possible to replace this class with your own 7 * by setting the $wpdb global variable in wp-content/db.php 8 * file to your class. The wpdb class will still be included, 9 * so you can extend it or simply use your own. 10 * 11 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 12 * 13 * @package WordPress 14 * @subpackage Database 15 * @since 0.71 16 */ 17 class wpdb_driver_mysql implements wpdb_driver { 18 19 /** 20 * Database link 21 * @var resource 22 */ 23 private $dbh = null; 24 25 /** 26 * Result set 27 * @var resource 28 */ 29 private $result = null; 30 31 /** 32 * Cached column info 33 * @var array|null 34 */ 35 private $col_info = null; 36 37 /** 38 * Escape with mysql_real_escape_string() 39 * @param string $string 40 * @return string 41 */ 42 public function escape( $string ) { 43 return mysql_real_escape_string( $string, $this->dbh ); 44 } 45 46 /** 47 * Get the latest error message from the DB driver 48 * @return string 49 */ 50 public function get_error_message() { 51 return mysql_error( $this->dbh ); 52 } 53 54 /** 55 * Free memory associated with the resultset 56 * @return void 57 */ 58 public function flush() { 59 if ( is_resource( $this->result ) ) { 60 mysql_free_result( $this->result ); 61 } 62 $this->result = null; 63 $this->col_info = null; 64 } 65 66 /** 67 * Connect to database 68 * @return bool 69 */ 70 public function connect( $host, $user, $pass, $port = 3306 ) { 71 72 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; 73 $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; 74 75 if ( WP_DEBUG ) { 76 $this->dbh = mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 77 } else { 78 $this->dbh = @mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 79 } 80 return ( false !== $this->dbh ); 81 } 82 83 /** 84 * Select database 85 * @return void 86 */ 87 public function select( $db ) { 88 if ( WP_DEBUG ) { 89 mysql_select_db( $db, $this->dbh ); 90 } else { 91 @mysql_select_db( $db, $this->dbh ); 92 } 93 } 94 95 /** 96 * Perform a MySQL database query, using current database connection. 97 * @param string $query Database query 98 * @return int|false Number of rows affected/selected or false on error 99 */ 100 public function query( $query ) { 101 $this->result = @mysql_query( $query, $this->dbh ); 102 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 103 $return_val = $this->result; 104 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 105 $return_val = $this->affected_rows(); 106 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 107 return is_resource( $this->result ) ? mysql_num_rows( $this->result ) : false ; 108 } 109 return true; 110 } 111 112 /** 113 * Get number of rows affected 114 * @return int 115 */ 116 public function affected_rows() { 117 return mysql_affected_rows( $this->dbh ); 118 } 119 120 /** 121 * Get last insert id 122 * @return int 123 */ 124 public function insert_id() { 125 return mysql_insert_id( $this->dbh ); 126 } 127 128 /** 129 * Get results 130 * @return array 131 */ 132 public function get_results() { 133 $ret = array(); 134 while ( $row = @mysql_fetch_object( $this->result ) ) { 135 $ret[] = $row; 136 } 137 return $ret; 138 } 139 140 /** 141 * Load the column metadata from the last query. 142 * @return array 143 */ 144 public function load_col_info() { 145 if ( $this->col_info ) 146 return $this->col_info; 147 for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) { 148 $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); 149 } 150 return $this->col_info; 151 } 152 153 /** 154 * The database version number. 155 * @return false|string false on failure, version number on success 156 */ 157 public function db_version() { 158 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 159 } 160 } 161 <?php 162 163 /** 164 * WordPress Database Access Abstraction Object 165 * 166 * It is possible to replace this class with your own 167 * by setting the $wpdb global variable in wp-content/db.php 168 * file to your class. The wpdb class will still be included, 169 * so you can extend it or simply use your own. 170 * 171 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 172 * 173 * @package WordPress 174 * @subpackage Database 175 * @since 0.71 176 */ 177 class wpdb_driver_mysql implements wpdb_driver { 178 179 /** 180 * Database link 181 * @var resource 182 */ 183 private $dbh = null; 184 185 /** 186 * Result set 187 * @var resource 188 */ 189 private $result = null; 190 191 /** 192 * Cached column info 193 * @var array|null 194 */ 195 private $col_info = null; 196 197 /** 198 * Escape with mysql_real_escape_string() 199 * @param string $string 200 * @return string 201 */ 202 public function escape( $string ) { 203 return mysql_real_escape_string( $string, $this->dbh ); 204 } 205 206 /** 207 * Get the latest error message from the DB driver 208 * @return string 209 */ 210 public function get_error_message() { 211 return mysql_error( $this->dbh ); 212 } 213 214 /** 215 * Free memory associated with the resultset 216 * @return void 217 */ 218 public function flush() { 219 if ( is_resource( $this->result ) ) { 220 mysql_free_result( $this->result ); 221 } 222 $this->result = null; 223 $this->col_info = null; 224 } 225 226 /** 227 * Connect to database 228 * @return bool 229 */ 230 public function connect( $host, $user, $pass, $port = 3306 ) { 231 232 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; 233 $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; 234 235 if ( WP_DEBUG ) { 236 $this->dbh = mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 237 } else { 238 $this->dbh = @mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 239 } 240 return ( false !== $this->dbh ); 241 } 242 243 /** 244 * Select database 245 * @return void 246 */ 247 public function select( $db ) { 248 if ( WP_DEBUG ) { 249 mysql_select_db( $db, $this->dbh ); 250 } else { 251 @mysql_select_db( $db, $this->dbh ); 252 } 253 } 254 255 /** 256 * Perform a MySQL database query, using current database connection. 257 * @param string $query Database query 258 * @return int|false Number of rows affected/selected or false on error 259 */ 260 public function query( $query ) { 261 $this->result = @mysql_query( $query, $this->dbh ); 262 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 263 $return_val = $this->result; 264 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 265 $return_val = $this->affected_rows(); 266 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 267 return mysql_num_rows( $this->result ); 268 } 269 return true; 270 } 271 272 /** 273 * Get number of rows affected 274 * @return int 275 */ 276 public function affected_rows() { 277 return mysql_affected_rows( $this->dbh ); 278 } 279 280 /** 281 * Get last insert id 282 * @return int 283 */ 284 public function insert_id() { 285 return mysql_insert_id( $this->dbh ); 286 } 287 288 /** 289 * Get results 290 * @return array 291 */ 292 public function get_results() { 293 $ret = array(); 294 while ( $row = @mysql_fetch_object( $this->result ) ) { 295 $ret[] = $row; 296 } 297 return $ret; 298 } 299 300 /** 301 * Load the column metadata from the last query. 302 * @return array 303 */ 304 public function load_col_info() { 305 if ( $this->col_info ) 306 return $this->col_info; 307 for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) { 308 $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); 309 } 310 return $this->col_info; 311 } 312 313 /** 314 * The database version number. 315 * @return false|string false on failure, version number on success 316 */ 317 public function db_version() { 318 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 319 } 320 } 321 <?php 322 323 /** 324 * WordPress Database Access Abstraction Object 325 * 326 * It is possible to replace this class with your own 327 * by setting the $wpdb global variable in wp-content/db.php 328 * file to your class. The wpdb class will still be included, 329 * so you can extend it or simply use your own. 330 * 331 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 332 * 333 * @package WordPress 334 * @subpackage Database 335 * @since 0.71 336 */ 337 class wpdb_driver_mysql implements wpdb_driver { 338 339 /** 340 * Database link 341 * @var resource 342 */ 343 private $dbh = null; 344 345 /** 346 * Result set 347 * @var resource 348 */ 349 private $result = null; 350 351 /** 352 * Cached column info 353 * @var array|null 354 */ 355 private $col_info = null; 356 357 /** 358 * Escape with mysql_real_escape_string() 359 * @param string $string 360 * @return string 361 */ 362 public function escape( $string ) { 363 return mysql_real_escape_string( $string, $this->dbh ); 364 } 365 366 /** 367 * Get the latest error message from the DB driver 368 * @return string 369 */ 370 public function get_error_message() { 371 return mysql_error( $this->dbh ); 372 } 373 374 /** 375 * Free memory associated with the resultset 376 * @return void 377 */ 378 public function flush() { 379 if ( is_resource( $this->result ) ) { 380 mysql_free_result( $this->result ); 381 } 382 $this->result = null; 383 $this->col_info = null; 384 } 385 386 /** 387 * Connect to database 388 * @return bool 389 */ 390 public function connect( $host, $user, $pass, $port = 3306 ) { 391 if ( WP_DEBUG ) { 392 $this->dbh = mysql_connect( $host, $user, $pass, true ); 393 } else { 394 $this->dbh = @mysql_connect( $host, $user, $pass, true ); 395 } 396 return ( false !== $this->dbh ); 397 } 398 399 /** 400 * Select database 401 * @return void 402 */ 403 public function select( $db ) { 404 if ( WP_DEBUG ) { 405 mysql_select_db( $db, $this->dbh ); 406 } else { 407 @mysql_select_db( $db, $this->dbh ); 408 } 409 } 410 411 /** 412 * Perform a MySQL database query, using current database connection. 413 * @param string $query Database query 414 * @return int|false Number of rows affected/selected or false on error 415 */ 416 public function query( $query ) { 417 $this->result = @mysql_query( $query, $this->dbh ); 418 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 419 $return_val = $this->result; 420 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 421 $return_val = $this->affected_rows(); 422 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 423 return mysql_num_rows( $this->result ); 424 } 425 return true; 426 } 427 428 /** 429 * Get number of rows affected 430 * @return int 431 */ 432 public function affected_rows() { 433 return mysql_affected_rows( $this->dbh ); 434 } 435 436 /** 437 * Get last insert id 438 * @return int 439 */ 440 public function insert_id() { 441 return mysql_insert_id( $this->dbh ); 442 } 443 444 /** 445 * Get results 446 * @return array 447 */ 448 public function get_results() { 449 $ret = array(); 450 while ( $row = @mysql_fetch_object( $this->result ) ) { 451 $ret[] = $row; 452 } 453 return $ret; 454 } 455 456 /** 457 * Load the column metadata from the last query. 458 * @return array 459 */ 460 public function load_col_info() { 461 if ( $this->col_info ) 462 return $this->col_info; 463 for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) { 464 $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); 465 } 466 return $this->col_info; 467 } 468 469 /** 470 * The database version number. 471 * @return false|string false on failure, version number on success 472 */ 473 public function db_version() { 474 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 475 } 476 } 477 No newline at end of file -
new file wp-includes/wp-db-driver-mysqli.php
diff --git wp-includes/wp-db-driver-mysqli.php wp-includes/wp-db-driver-mysqli.php new file mode 100644 index 0000000..fc028c5
- + 1 <?php 2 3 /** 4 * WordPress Database Access Abstraction Object 5 * 6 * It is possible to replace this class with your own 7 * by setting the $wpdb global variable in wp-content/db.php 8 * file to your class. The wpdb class will still be included, 9 * so you can extend it or simply use your own. 10 * 11 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 12 * 13 * @package WordPress 14 * @subpackage Database 15 * @since 0.71 16 */ 17 class wpdb_driver_mysqli implements wpdb_driver { 18 19 /** 20 * Database link 21 * @var mysqli 22 */ 23 private $dbh = null; 24 25 /** 26 * Result set 27 * @var mysqli_stmt|mysqli_result 28 */ 29 private $result = null; 30 31 /** 32 * Cached column info 33 * @var array|null 34 */ 35 private $col_info = null; 36 37 /** 38 * Escape with mysql_real_escape_string() 39 * @param string $string 40 * @return string 41 */ 42 public function escape( $string ) { 43 return $this->dbh->escape_string( $string ); 44 } 45 46 /** 47 * Get the latest error message from the DB driver 48 * @return string 49 */ 50 public function get_error_message() { 51 return $this->dbh->error; 52 } 53 54 /** 55 * Free memory associated with the resultset 56 * @return void 57 */ 58 public function flush() { 59 if ( $this->result instanceof mysqli_stmt ) { 60 $this->result->free_result(); 61 } 62 $this->result = null; 63 $this->col_info = null; 64 } 65 66 /** 67 * Connect to database 68 * @return bool 69 */ 70 public function connect( $host, $user, $pass, $port = 3306 ) { 71 $this->dbh = new mysqli( $host, $user, $pass, '', $port ); 72 return ( !mysqli_connect_error() ); 73 } 74 75 /** 76 * Select database 77 * @return void 78 */ 79 public function select( $db ) { 80 $this->dbh->select_db( $db ); 81 } 82 83 /** 84 * Perform a MySQL database query, using current database connection. 85 * @param string $query Database query 86 * @return int|false Number of rows affected/selected or false on error 87 */ 88 public function query( $query ) { 89 $this->result = $this->dbh->query( $query ); 90 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 91 $return_val = $this->result; 92 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 93 $return_val = $this->affected_rows(); 94 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 95 return $this->result->num_rows; 96 } 97 return true; 98 } 99 100 /** 101 * Get number of rows affected 102 * @return int 103 */ 104 public function affected_rows() { 105 return $this->dbh->affected_rows; 106 } 107 108 /** 109 * Get last insert id 110 * @return int 111 */ 112 public function insert_id() { 113 return $this->dbh->insert_id; 114 } 115 116 /** 117 * Get results 118 * @return array 119 */ 120 public function get_results() { 121 $ret = array(); 122 while ( $row = $this->result->fetch_object() ) { 123 $ret[] = $row; 124 } 125 return $ret; 126 } 127 128 /** 129 * Load the column metadata from the last query. 130 * @return array 131 */ 132 public function load_col_info() { 133 if ( $this->col_info ) 134 return $this->col_info; 135 for ( $i = 0; $i < $this->result->field_count ; $i++ ) { 136 $this->col_info[ $i ] = $this->result->fetch_field_direct( $i ); 137 } 138 return $this->col_info; 139 } 140 141 /** 142 * The database version number. 143 * @return false|string false on failure, version number on success 144 */ 145 public function db_version() { 146 return preg_replace( '/[^0-9.].*/', '', $this->dbh->server_version ); 147 } 148 } 149 <?php 150 151 /** 152 * WordPress Database Access Abstraction Object 153 * 154 * It is possible to replace this class with your own 155 * by setting the $wpdb global variable in wp-content/db.php 156 * file to your class. The wpdb class will still be included, 157 * so you can extend it or simply use your own. 158 * 159 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 160 * 161 * @package WordPress 162 * @subpackage Database 163 * @since 0.71 164 */ 165 class wpdb_driver_mysqli implements wpdb_driver { 166 167 /** 168 * Database link 169 * @var mysqli 170 */ 171 private $dbh = null; 172 173 /** 174 * Result set 175 * @var mysqli_stmt|mysqli_result 176 */ 177 private $result = null; 178 179 /** 180 * Cached column info 181 * @var array|null 182 */ 183 private $col_info = null; 184 185 /** 186 * Escape with mysql_real_escape_string() 187 * @param string $string 188 * @return string 189 */ 190 public function escape( $string ) { 191 return $this->dbh->escape_string( $string ); 192 } 193 194 /** 195 * Get the latest error message from the DB driver 196 * @return string 197 */ 198 public function get_error_message() { 199 return $this->dbh->error; 200 } 201 202 /** 203 * Free memory associated with the resultset 204 * @return void 205 */ 206 public function flush() { 207 if ( $this->result instanceof mysqli_stmt ) { 208 $this->result->free_result(); 209 } 210 $this->result = null; 211 $this->col_info = null; 212 } 213 214 /** 215 * Connect to database 216 * @return bool 217 */ 218 public function connect( $host, $user, $pass, $port = 3306 ) { 219 $this->dbh = new mysqli( $host, $user, $pass, '', $port ); 220 return ( !mysqli_connect_error() ); 221 } 222 223 /** 224 * Select database 225 * @return void 226 */ 227 public function select( $db ) { 228 $this->dbh->select_db( $db ); 229 } 230 231 /** 232 * Perform a MySQL database query, using current database connection. 233 * @param string $query Database query 234 * @return int|false Number of rows affected/selected or false on error 235 */ 236 public function query( $query ) { 237 $this->result = $this->dbh->query( $query ); 238 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 239 $return_val = $this->result; 240 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 241 $return_val = $this->affected_rows(); 242 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 243 return $this->result->num_rows; 244 } 245 return true; 246 } 247 248 /** 249 * Get number of rows affected 250 * @return int 251 */ 252 public function affected_rows() { 253 return $this->dbh->affected_rows; 254 } 255 256 /** 257 * Get last insert id 258 * @return int 259 */ 260 public function insert_id() { 261 return $this->dbh->insert_id; 262 } 263 264 /** 265 * Get results 266 * @return array 267 */ 268 public function get_results() { 269 $ret = array(); 270 while ( $row = $this->result->fetch_object() ) { 271 $ret[] = $row; 272 } 273 return $ret; 274 } 275 276 /** 277 * Load the column metadata from the last query. 278 * @return array 279 */ 280 public function load_col_info() { 281 if ( $this->col_info ) 282 return $this->col_info; 283 for ( $i = 0; $i < $this->result->field_count ; $i++ ) { 284 $this->col_info[ $i ] = $this->result->fetch_field_direct( $i ); 285 } 286 return $this->col_info; 287 } 288 289 /** 290 * The database version number. 291 * @return false|string false on failure, version number on success 292 */ 293 public function db_version() { 294 return preg_replace( '/[^0-9.].*/', '', $this->dbh->server_version ); 295 } 296 } 297 <?php 298 299 /** 300 * WordPress Database Access Abstraction Object 301 * 302 * It is possible to replace this class with your own 303 * by setting the $wpdb global variable in wp-content/db.php 304 * file to your class. The wpdb class will still be included, 305 * so you can extend it or simply use your own. 306 * 307 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 308 * 309 * @package WordPress 310 * @subpackage Database 311 * @since 0.71 312 */ 313 class wpdb_driver_mysqli implements wpdb_driver { 314 315 /** 316 * Database link 317 * @var mysqli 318 */ 319 private $dbh = null; 320 321 /** 322 * Result set 323 * @var mysqli_stmt|mysqli_result 324 */ 325 private $result = null; 326 327 /** 328 * Cached column info 329 * @var array|null 330 */ 331 private $col_info = null; 332 333 /** 334 * Escape with mysql_real_escape_string() 335 * @param string $string 336 * @return string 337 */ 338 public function escape( $string ) { 339 return $this->dbh->escape_string( $string ); 340 } 341 342 /** 343 * Get the latest error message from the DB driver 344 * @return string 345 */ 346 public function get_error_message() { 347 return $this->dbh->error; 348 } 349 350 /** 351 * Free memory associated with the resultset 352 * @return void 353 */ 354 public function flush() { 355 if ( $this->result instanceof mysqli_stmt ) { 356 $this->result->free_result(); 357 } 358 $this->result = null; 359 $this->col_info = null; 360 } 361 362 /** 363 * Connect to database 364 * @return bool 365 */ 366 public function connect( $host, $user, $pass, $port = 3306 ) { 367 $this->dbh = new mysqli( $host, $user, $pass, '', $port ); 368 return ( !mysqli_connect_error() ); 369 } 370 371 /** 372 * Select database 373 * @return void 374 */ 375 public function select( $db ) { 376 $this->dbh->select_db( $db ); 377 } 378 379 /** 380 * Perform a MySQL database query, using current database connection. 381 * @param string $query Database query 382 * @return int|false Number of rows affected/selected or false on error 383 */ 384 public function query( $query ) { 385 $this->result = $this->dbh->query( $query ); 386 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 387 $return_val = $this->result; 388 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 389 $return_val = $this->affected_rows(); 390 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 391 return $this->result->num_rows; 392 } 393 return true; 394 } 395 396 /** 397 * Get number of rows affected 398 * @return int 399 */ 400 public function affected_rows() { 401 return $this->dbh->affected_rows; 402 } 403 404 /** 405 * Get last insert id 406 * @return int 407 */ 408 public function insert_id() { 409 return $this->dbh->insert_id; 410 } 411 412 /** 413 * Get results 414 * @return array 415 */ 416 public function get_results() { 417 $ret = array(); 418 while ( $row = $this->result->fetch_object() ) { 419 $ret[] = $row; 420 } 421 return $ret; 422 } 423 424 /** 425 * Load the column metadata from the last query. 426 * @return array 427 */ 428 public function load_col_info() { 429 if ( $this->col_info ) 430 return $this->col_info; 431 for ( $i = 0; $i < $this->result->field_count ; $i++ ) { 432 $this->col_info[ $i ] = $this->result->fetch_field_direct( $i ); 433 } 434 return $this->col_info; 435 } 436 437 /** 438 * The database version number. 439 * @return false|string false on failure, version number on success 440 */ 441 public function db_version() { 442 return preg_replace( '/[^0-9.].*/', '', $this->dbh->server_version ); 443 } 444 } 445 No newline at end of file -
new file wp-includes/wp-db-driver-pdo_mysql.php
diff --git wp-includes/wp-db-driver-pdo_mysql.php wp-includes/wp-db-driver-pdo_mysql.php new file mode 100644 index 0000000..b8850bd
- + 1 <?php 2 3 /** 4 * WordPress Database Access Abstraction Object 5 * 6 * It is possible to replace this class with your own 7 * by setting the $wpdb global variable in wp-content/db.php 8 * file to your class. The wpdb class will still be included, 9 * so you can extend it or simply use your own. 10 * 11 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 12 * 13 * @package WordPress 14 * @subpackage Database 15 * @since 0.71 16 */ 17 class wpdb_driver_pdo_mysql implements wpdb_driver { 18 19 /** 20 * Database link 21 * @var PDO 22 */ 23 private $dbh = null; 24 25 /** 26 * Result set 27 * @var PDOStatement 28 */ 29 private $result = null; 30 31 /** 32 * Cached column info 33 * @var array|null 34 */ 35 private $col_info = null; 36 37 /** 38 * Array of fetched rows. 39 * PDO doesn't have a "count rows" feature, so we have to fetch the rows 40 * up front, and cache them here 41 * @var array 42 */ 43 private $fetched_rows = array(); 44 45 /** 46 * Escape with mysql_real_escape_string() 47 * @param string $string 48 * @return string 49 */ 50 public function escape( $string ) { 51 return substr( $this->dbh->quote( $string ), 1, -1 ); 52 } 53 54 /** 55 * Get the latest error message from the DB driver 56 * @return string 57 */ 58 public function get_error_message() { 59 $error = $this->dbh->errorInfo(); 60 return $error[2]; 61 } 62 63 /** 64 * Free memory associated with the resultset 65 * @return void 66 */ 67 public function flush() { 68 if ( $this->result instanceof PDOStatement ) { 69 $this->result->closeCursor(); 70 } 71 $this->result = null; 72 $this->col_info = null; 73 $this->fetched_rows = array(); 74 } 75 76 /** 77 * Connect to database 78 * @return bool 79 */ 80 public function connect( $host, $user, $pass, $port = 3306 ) { 81 $dsn = sprintf( 'mysql:host=%1$s;port=%2$d', $host, $port ); 82 try { 83 $this->dbh = new PDO( $dsn, $user, $pass ); 84 } catch ( Exception $e ) { 85 return false; 86 } 87 return true; 88 } 89 90 /** 91 * Select database 92 * @return void 93 */ 94 public function select( $db ) { 95 $this->dbh->exec( sprintf( 'USE %s', $db ) ); 96 } 97 98 /** 99 * Perform a MySQL database query, using current database connection. 100 * @param string $query Database query 101 * @return int|false Number of rows affected/selected or false on error 102 */ 103 public function query( $query ) { 104 try { 105 $this->result = $this->dbh->query( $query ); 106 } catch ( Exception $e ) { 107 } 108 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 109 $return_val = $this->result; 110 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 111 $return_val = $this->affected_rows(); 112 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 113 $this->get_results(); 114 return count( $this->fetched_rows ); 115 } 116 return true; 117 } 118 119 /** 120 * Get number of rows affected 121 * @return int 122 */ 123 public function affected_rows() { 124 return $this->result->rowCount(); 125 } 126 127 /** 128 * Get last insert id 129 * @return int 130 */ 131 public function insert_id() { 132 return $this->dbh->lastInsertId(); 133 } 134 135 /** 136 * Get results 137 * @return array 138 */ 139 public function get_results() { 140 if ( !empty( $this->fetched_rows ) ) { 141 return $this->fetched_rows; 142 } 143 $this->fetched_rows = array(); 144 while ( $row = $this->result->fetchObject() ) { 145 $this->fetched_rows[] = $row; 146 } 147 return $this->fetched_rows; 148 } 149 150 /** 151 * Load the column metadata from the last query. 152 * @return array 153 */ 154 public function load_col_info() { 155 if ( $this->col_info ) 156 return $this->col_info; 157 for ( $i = 0; $i < $this->result->columnCount() ; $i++ ) { 158 $this->col_info[ $i ] = $this->result->fetchColumn( $i ); 159 } 160 return $this->col_info; 161 } 162 163 /** 164 * The database version number. 165 * @return false|string false on failure, version number on success 166 */ 167 public function db_version() { 168 return preg_replace( '/[^0-9.].*/', '', $this->dbh->getAttribute( PDO::ATTR_SERVER_VERSION ) ); 169 } 170 } 171 <?php 172 173 /** 174 * WordPress Database Access Abstraction Object 175 * 176 * It is possible to replace this class with your own 177 * by setting the $wpdb global variable in wp-content/db.php 178 * file to your class. The wpdb class will still be included, 179 * so you can extend it or simply use your own. 180 * 181 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 182 * 183 * @package WordPress 184 * @subpackage Database 185 * @since 0.71 186 */ 187 class wpdb_driver_pdo_mysql implements wpdb_driver { 188 189 /** 190 * Database link 191 * @var PDO 192 */ 193 private $dbh = null; 194 195 /** 196 * Result set 197 * @var PDOStatement 198 */ 199 private $result = null; 200 201 /** 202 * Cached column info 203 * @var array|null 204 */ 205 private $col_info = null; 206 207 /** 208 * Array of fetched rows. 209 * PDO doesn't have a "count rows" feature, so we have to fetch the rows 210 * up front, and cache them here 211 * @var array 212 */ 213 private $fetched_rows = array(); 214 215 /** 216 * Escape with mysql_real_escape_string() 217 * @param string $string 218 * @return string 219 */ 220 public function escape( $string ) { 221 return substr( $this->dbh->quote( $string ), 1, -1 ); 222 } 223 224 /** 225 * Get the latest error message from the DB driver 226 * @return string 227 */ 228 public function get_error_message() { 229 $error = $this->dbh->errorInfo(); 230 return $error[2]; 231 } 232 233 /** 234 * Free memory associated with the resultset 235 * @return void 236 */ 237 public function flush() { 238 if ( $this->result instanceof PDOStatement ) { 239 $this->result->closeCursor(); 240 } 241 $this->result = null; 242 $this->col_info = null; 243 $this->fetched_rows = array(); 244 } 245 246 /** 247 * Connect to database 248 * @return bool 249 */ 250 public function connect( $host, $user, $pass, $port = 3306 ) { 251 $dsn = sprintf( 'mysql:host=%1$s;port=%2$d', $host, $port ); 252 try { 253 $this->dbh = new PDO( $dsn, $user, $pass ); 254 } catch ( Exception $e ) { 255 return false; 256 } 257 return true; 258 } 259 260 /** 261 * Select database 262 * @return void 263 */ 264 public function select( $db ) { 265 $this->dbh->exec( sprintf( 'USE %s', $db ) ); 266 } 267 268 /** 269 * Perform a MySQL database query, using current database connection. 270 * @param string $query Database query 271 * @return int|false Number of rows affected/selected or false on error 272 */ 273 public function query( $query ) { 274 try { 275 $this->result = $this->dbh->query( $query ); 276 } catch ( Exception $e ) { 277 } 278 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 279 $return_val = $this->result; 280 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 281 $return_val = $this->affected_rows(); 282 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 283 $this->get_results(); 284 return count( $this->fetched_rows ); 285 } 286 return true; 287 } 288 289 /** 290 * Get number of rows affected 291 * @return int 292 */ 293 public function affected_rows() { 294 return $this->result->rowCount(); 295 } 296 297 /** 298 * Get last insert id 299 * @return int 300 */ 301 public function insert_id() { 302 return $this->dbh->lastInsertId(); 303 } 304 305 /** 306 * Get results 307 * @return array 308 */ 309 public function get_results() { 310 if ( !empty( $this->fetched_rows ) ) { 311 return $this->fetched_rows; 312 } 313 $this->fetched_rows = array(); 314 while ( $row = $this->result->fetchObject() ) { 315 $this->fetched_rows[] = $row; 316 } 317 return $this->fetched_rows; 318 } 319 320 /** 321 * Load the column metadata from the last query. 322 * @return array 323 */ 324 public function load_col_info() { 325 if ( $this->col_info ) 326 return $this->col_info; 327 for ( $i = 0; $i < $this->result->columnCount() ; $i++ ) { 328 $this->col_info[ $i ] = $this->result->fetchColumn( $i ); 329 } 330 return $this->col_info; 331 } 332 333 /** 334 * The database version number. 335 * @return false|string false on failure, version number on success 336 */ 337 public function db_version() { 338 return preg_replace( '/[^0-9.].*/', '', $this->dbh->getAttribute( PDO::ATTR_SERVER_VERSION ) ); 339 } 340 } 341 <?php 342 343 /** 344 * WordPress Database Access Abstraction Object 345 * 346 * It is possible to replace this class with your own 347 * by setting the $wpdb global variable in wp-content/db.php 348 * file to your class. The wpdb class will still be included, 349 * so you can extend it or simply use your own. 350 * 351 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 352 * 353 * @package WordPress 354 * @subpackage Database 355 * @since 0.71 356 */ 357 class wpdb_driver_pdo_mysql implements wpdb_driver { 358 359 /** 360 * Database link 361 * @var PDO 362 */ 363 private $dbh = null; 364 365 /** 366 * Result set 367 * @var PDOStatement 368 */ 369 private $result = null; 370 371 /** 372 * Cached column info 373 * @var array|null 374 */ 375 private $col_info = null; 376 377 /** 378 * Array of fetched rows. 379 * PDO doesn't have a "count rows" feature, so we have to fetch the rows 380 * up front, and cache them here 381 * @var array 382 */ 383 private $fetched_rows = array(); 384 385 /** 386 * Escape with mysql_real_escape_string() 387 * @param string $string 388 * @return string 389 */ 390 public function escape( $string ) { 391 return substr( $this->dbh->quote( $string ), 1, -1 ); 392 } 393 394 /** 395 * Get the latest error message from the DB driver 396 * @return string 397 */ 398 public function get_error_message() { 399 $error = $this->dbh->errorInfo(); 400 return $error[2]; 401 } 402 403 /** 404 * Free memory associated with the resultset 405 * @return void 406 */ 407 public function flush() { 408 if ( $this->result instanceof PDOStatement ) { 409 $this->result->closeCursor(); 410 } 411 $this->result = null; 412 $this->col_info = null; 413 $this->fetched_rows = array(); 414 } 415 416 /** 417 * Connect to database 418 * @return bool 419 */ 420 public function connect( $host, $user, $pass, $port = 3306 ) { 421 $dsn = sprintf( 'mysql:host=%1$s;port=%2$d', $host, $port ); 422 try { 423 $this->dbh = new PDO( $dsn, $user, $pass ); 424 } catch ( Exception $e ) { 425 return false; 426 } 427 return true; 428 } 429 430 /** 431 * Select database 432 * @return void 433 */ 434 public function select( $db ) { 435 $this->dbh->exec( sprintf( 'USE %s', $db ) ); 436 } 437 438 /** 439 * Perform a MySQL database query, using current database connection. 440 * @param string $query Database query 441 * @return int|false Number of rows affected/selected or false on error 442 */ 443 public function query( $query ) { 444 try { 445 $this->result = $this->dbh->query( $query ); 446 } catch ( Exception $e ) { 447 } 448 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 449 $return_val = $this->result; 450 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 451 $return_val = $this->affected_rows(); 452 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 453 $this->get_results(); 454 return count( $this->fetched_rows ); 455 } 456 return true; 457 } 458 459 /** 460 * Get number of rows affected 461 * @return int 462 */ 463 public function affected_rows() { 464 return $this->result->rowCount(); 465 } 466 467 /** 468 * Get last insert id 469 * @return int 470 */ 471 public function insert_id() { 472 return $this->dbh->lastInsertId(); 473 } 474 475 /** 476 * Get results 477 * @return array 478 */ 479 public function get_results() { 480 if ( !empty( $this->fetched_rows ) ) { 481 return $this->fetched_rows; 482 } 483 $this->fetched_rows = array(); 484 while ( $row = $this->result->fetchObject() ) { 485 $this->fetched_rows[] = $row; 486 } 487 return $this->fetched_rows; 488 } 489 490 /** 491 * Load the column metadata from the last query. 492 * @return array 493 */ 494 public function load_col_info() { 495 if ( $this->col_info ) 496 return $this->col_info; 497 for ( $i = 0; $i < $this->result->columnCount() ; $i++ ) { 498 $this->col_info[ $i ] = $this->result->fetchColumn( $i ); 499 } 500 return $this->col_info; 501 } 502 503 /** 504 * The database version number. 505 * @return false|string false on failure, version number on success 506 */ 507 public function db_version() { 508 return preg_replace( '/[^0-9.].*/', '', $this->dbh->getAttribute( PDO::ATTR_SERVER_VERSION ) ); 509 } 510 } 511 No newline at end of file -
new file wp-includes/wp-db-driver.interface.php
diff --git wp-includes/wp-db-driver.interface.php wp-includes/wp-db-driver.interface.php new file mode 100644 index 0000000..efc6046
- + 1 <?php 2 3 interface wpdb_driver { 4 public function escape( $string ); 5 public function get_error_message(); 6 public function flush(); 7 public function connect( $host, $user, $pass, $port = 3306 ); 8 public function select( $name ); 9 public function query( $query ); 10 public function load_col_info(); 11 public function db_version(); 12 public function affected_rows(); 13 public function insert_id(); 14 public function get_results(); 15 } 16 <?php 17 18 interface wpdb_driver { 19 public function escape( $string ); 20 public function get_error_message(); 21 public function flush(); 22 public function connect( $host, $user, $pass, $port = 3306 ); 23 public function select( $name ); 24 public function query( $query ); 25 public function load_col_info(); 26 public function db_version(); 27 public function affected_rows(); 28 public function insert_id(); 29 public function get_results(); 30 } 31 <?php 32 33 interface wpdb_driver { 34 public function escape( $string ); 35 public function get_error_message(); 36 public function flush(); 37 public function connect( $host, $user, $pass, $port = 3306 ); 38 public function select( $name ); 39 public function query( $query ); 40 public function load_col_info(); 41 public function db_version(); 42 public function affected_rows(); 43 public function insert_id(); 44 public function get_results(); 45 } -
wp-includes/wp-db.php
diff --git wp-includes/wp-db.php wp-includes/wp-db.php index 391cfa4..44b70a1 100644
class wpdb { 487 487 protected $dbhost; 488 488 489 489 /** 490 * Database Handle490 * Database driver object 491 491 * 492 * @since 0.71 492 * Allow for simple, and backwards compatible, pluggable database drivers 493 * like PDO_mysql and mysqli to power wpdb 494 * 493 495 * @access protected 494 * @var string 496 * @since 3.5.0 497 * @var wpdb_driver 495 498 */ 496 499 protected $dbh; 497 500 … … class wpdb { 518 521 */ 519 522 public $is_mysql = null; 520 523 521 /** 524 /** 525 * Pick the adapter to be used for performing the actual queries. 526 * 527 * @since 3.6.0 528 */ 529 private function set_driver() { 530 531 // Auto-pick the driver 532 if ( defined( 'WPDB_DRIVER' ) ) { 533 $driver = WPDB_DRIVER; 534 } elseif ( extension_loaded( 'pdo_mysql' ) ) { 535 $driver = 'pdo_mysql'; 536 } elseif ( extension_loaded( 'mysqli' ) ) { 537 $driver = 'mysqli'; 538 } elseif ( extension_loaded( 'mysql' ) ) { 539 $driver = 'mysql'; 540 } 541 542 // Get the new driver 543 if ( in_array( $driver, array( 'mysql', 'mysqli', 'pdo_mysql' ) ) ) { 544 require_once( ABSPATH . WPINC . '/class-wp-db-driver-' . $driver . '.php' ); 545 } 546 $class = 'wpdb_driver_' . $driver; 547 548 if ( !class_exists( $class ) ) { 549 wp_load_translations_early(); 550 $this->bail( sprintf( __( " 551 <h1>No database drivers found</h1>. 552 <p>WordPress requires the mysql, mysqli, or pdo_mysql extension to talk to your database.</p> 553 <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> 554 "), 'db_connect_fail' ) ); 555 } 556 557 $this->dbh = new $class(); 558 } 559 560 /** 522 561 * Connects to the database server and selects a database 523 562 * 524 563 * PHP5 style constructor for compatibility with PHP5. Does … … class wpdb { 534 573 * @param string $dbhost MySQL database host 535 574 */ 536 575 function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { 576 $this->set_driver(); 577 537 578 register_shutdown_function( array( $this, '__destruct' ) ); 538 579 539 580 if ( WP_DEBUG ) … … class wpdb { 646 687 if ( !isset($collate) ) 647 688 $collate = $this->collate; 648 689 if ( $this->has_cap( 'collation', $dbh ) && !empty( $charset ) ) { 649 if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset', $dbh ) ) { 650 mysql_set_charset( $charset, $dbh ); 651 $this->real_escape = true; 652 } else { 653 $query = $this->prepare( 'SET NAMES %s', $charset ); 654 if ( ! empty( $collate ) ) 655 $query .= $this->prepare( ' COLLATE %s', $collate ); 656 mysql_query( $query, $dbh ); 657 } 690 $query = $this->prepare( 'SET NAMES %s', $charset ); 691 if ( ! empty( $collate ) ) 692 $query .= $this->prepare( ' COLLATE %s', $collate ); 693 $this->dbh->query( $query ); 658 694 } 659 695 } 660 696 … … class wpdb { 837 873 * @return null Always null. 838 874 */ 839 875 function select( $db, $dbh = null ) { 840 if ( is_null($dbh) ) 841 $dbh = $this->dbh; 842 843 if ( !@mysql_select_db( $db, $dbh ) ) { 844 $this->ready = false; 845 wp_load_translations_early(); 846 $this->bail( sprintf( __( '<h1>Can’t select database</h1> 847 <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> 848 <ul> 849 <li>Are you sure it exists?</li> 850 <li>Does the user <code>%2$s</code> have permission to use the <code>%1$s</code> database?</li> 851 <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> 852 </ul> 853 <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' ); 854 return; 855 } 876 $this->dbh->select( $db ); 856 877 } 857 878 858 879 /** … … class wpdb { 882 903 */ 883 904 function _real_escape( $string ) { 884 905 if ( $this->dbh && $this->real_escape ) 885 return mysql_real_escape_string( $string, $this->dbh);906 return $this->dbh->escape( $string ); 886 907 else 887 908 return addslashes( $string ); 888 909 } … … class wpdb { 1017 1038 global $EZSQL_ERROR; 1018 1039 1019 1040 if ( !$str ) 1020 $str = mysql_error( $this->dbh);1041 $str = $this->dbh->get_error_message(); 1021 1042 $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str ); 1022 1043 1023 1044 if ( $this->suppress_errors ) … … class wpdb { 1114 1135 * @return void 1115 1136 */ 1116 1137 function flush() { 1117 $this->last_result = array(); 1118 $this->col_info = null; 1119 $this->last_query = null; 1120 1121 if ( is_resource( $this->result ) ) 1122 mysql_free_result( $this->result ); 1138 $this->dbh->flush(); 1123 1139 } 1124 1140 1125 1141 /** … … class wpdb { 1134 1150 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; 1135 1151 $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; 1136 1152 1137 if ( WP_DEBUG ) {1138 $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );1139 } else{1140 $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags);1141 }1153 $host = $this->dbhost; 1154 $port = 3306; 1155 if ( false !== strpos( $this->dbhost, ':' ) ) { 1156 list( $host, $port ) = explode( ':', $this->dbhost ); 1157 } 1142 1158 1143 if ( !$this->dbh ) {1159 if ( !$this->dbh->connect( $host, $this->dbuser, $this->dbpassword, $port ) ) { 1144 1160 wp_load_translations_early(); 1145 1161 $this->bail( sprintf( __( " 1146 1162 <h1>Error establishing a database connection</h1> … … class wpdb { 1192 1208 if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 1193 1209 $this->timer_start(); 1194 1210 1195 $ this->result = @mysql_query( $query, $this->dbh);1211 $result = $this->dbh->query( $query ); 1196 1212 $this->num_queries++; 1197 1213 1198 1214 if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 1199 1215 $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() ); 1200 1216 1201 1217 // If there is an error then take note of it.. 1202 if ( $this->last_error = mysql_error( $this->dbh) ) {1218 if ( $this->last_error = $this->dbh->get_error_message() ) { 1203 1219 $this->print_error(); 1204 1220 return false; 1205 1221 } … … class wpdb { 1207 1223 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 1208 1224 $return_val = $this->result; 1209 1225 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 1210 $this->rows_affected = mysql_affected_rows( $this->dbh);1226 $this->rows_affected = $this->dbh->affected_rows(); 1211 1227 // Take note of the insert_id 1212 1228 if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { 1213 $this->insert_id = mysql_insert_id($this->dbh);1229 $this->insert_id = $this->dbh->insert_id(); 1214 1230 } 1215 1231 // Return number of rows affected 1216 1232 $return_val = $this->rows_affected; 1217 1233 } else { 1218 $num_rows = 0; 1219 while ( $row = @mysql_fetch_object( $this->result ) ) { 1220 $this->last_result[$num_rows] = $row; 1221 $num_rows++; 1222 } 1223 1224 // Log number of rows the query returned 1225 // and return number of rows selected 1226 $this->num_rows = $num_rows; 1227 $return_val = $num_rows; 1234 $return_val = $this->num_rows = count( $this->last_result ); 1228 1235 } 1229 1236 1237 $this->last_result = $this->dbh->get_results(); 1230 1238 return $return_val; 1231 1239 } 1232 1240 … … class wpdb { 1556 1564 * @access protected 1557 1565 */ 1558 1566 protected function load_col_info() { 1559 if ( $this->col_info ) 1560 return; 1561 1562 for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) { 1563 $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); 1564 } 1567 $this->col_info = $this->dbh->load_col_info(); 1565 1568 } 1566 1569 1567 1570 /** … … class wpdb { 1732 1735 * @return false|string false on failure, version number on success 1733 1736 */ 1734 1737 function db_version() { 1735 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ));1738 return $this->dbh->db_version(); 1736 1739 } 1737 1740 }