Ticket #21663: 21663.diff
File 21663.diff, 22.3 KB (added by , 11 years ago) |
---|
-
src/wp-includes/drivers/class-wpdb-driver-mysql.php
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.8.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 $this->result = null; 57 $this->col_info = null; 58 } 59 60 /** 61 * Connect to database 62 * @return bool 63 */ 64 public function connect( $host, $user, $pass, $port = 3306, $options = array() ) { 65 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; 66 $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; 67 68 if ( WP_DEBUG ) { 69 $this->dbh = mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 70 } else { 71 $this->dbh = @mysql_connect( "$host:$port", $user, $pass, $new_link, $client_flags ); 72 } 73 return ( false !== $this->dbh ); 74 } 75 76 /** 77 * Select database 78 * @return void 79 */ 80 public function select( $db ) { 81 if ( WP_DEBUG ) { 82 return mysql_select_db( $db, $this->dbh ); 83 } else { 84 return @mysql_select_db( $db, $this->dbh ); 85 } 86 } 87 88 /** 89 * Perform a MySQL database query, using current database connection. 90 * @param string $query Database query 91 * @return int|false Number of rows affected/selected or false on error 92 */ 93 public function query( $query ) { 94 $return_val = 0; 95 $this->result = @mysql_query( $query, $this->dbh ); 96 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 105 return $return_val; 106 } 107 108 /** 109 * Get number of rows affected 110 * @return int 111 */ 112 public function affected_rows() { 113 return mysql_affected_rows( $this->dbh ); 114 } 115 116 /** 117 * Get last insert id 118 * @return int 119 */ 120 public function insert_id() { 121 return mysql_insert_id( $this->dbh ); 122 } 123 124 /** 125 * Get results 126 * @return array 127 */ 128 public function get_results() { 129 $ret = array(); 130 while ( $row = @mysql_fetch_object( $this->result ) ) { 131 $ret[] = $row; 132 } 133 return $ret; 134 } 135 136 /** 137 * Load the column metadata from the last query. 138 * @return array 139 */ 140 public function load_col_info() { 141 if ( $this->col_info ) 142 return $this->col_info; 143 for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) 144 $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); 145 146 return $this->col_info; 147 } 148 149 /** 150 * The database version number. 151 * @return false|string false on failure, version number on success 152 */ 153 public function db_version() { 154 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 155 } 156 } 157 No newline at end of file -
src/wp-includes/drivers/class-wpdb-driver-mysqli.php
Property changes on: src/wp-includes/drivers/class-wpdb-driver-mysql.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property
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.8.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, $options = array() ) { 66 $this->dbh = new mysqli( $host, $user, $pass, '', $port ); 67 68 if ( ! empty( $options['key'] ) && ! empty( $options['cert'] ) && ! empty( $options['ca'] ) ) { 69 $this->dbh->ssl_set( 70 $options['key'], 71 $options['cert'], 72 $options['ca'], 73 $options['ca_path'], 74 $options['cipher'] 75 ); 76 } 77 78 return ( ! mysqli_connect_error() ); 79 } 80 81 /** 82 * Select database 83 * @return void 84 */ 85 public function select( $db ) { 86 return $this->dbh->select_db( $db ); 87 } 88 89 /** 90 * Perform a MySQL database query, using current database connection. 91 * @param string $query Database query 92 * @return int|false Number of rows affected/selected or false on error 93 */ 94 public function query( $query ) { 95 $return_val = 0; 96 97 $this->result = $this->dbh->query( $query ); 98 99 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 100 $return_val = $this->result; 101 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 102 $return_val = $this->affected_rows(); 103 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 104 return is_object( $this->result ) ? $this->result->num_rows : false; 105 } 106 107 return $return_val; 108 } 109 110 /** 111 * Get number of rows affected 112 * @return int 113 */ 114 public function affected_rows() { 115 return $this->dbh->affected_rows; 116 } 117 118 /** 119 * Get last insert id 120 * @return int 121 */ 122 public function insert_id() { 123 return $this->dbh->insert_id; 124 } 125 126 /** 127 * Get results 128 * @return array 129 */ 130 public function get_results() { 131 $ret = array(); 132 133 if( is_object( $this->result ) ) { 134 while ( $row = $this->result->fetch_object() ) 135 $ret[] = $row; 136 } 137 138 return $ret; 139 } 140 141 /** 142 * Load the column metadata from the last query. 143 * @return array 144 */ 145 public function load_col_info() { 146 if ( $this->col_info ) 147 return $this->col_info; 148 for ( $i = 0; $i < $this->result->field_count ; $i++ ) 149 $this->col_info[ $i ] = $this->result->fetch_field_direct( $i ); 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.].*/', '', $this->dbh->server_version ); 159 } 160 } -
src/wp-includes/drivers/class-wpdb-driver-pdo_mysql.php
Property changes on: src/wp-includes/drivers/class-wpdb-driver-mysqli.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property
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.8.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 $this->result = null; 69 $this->col_info = null; 70 $this->fetched_rows = array(); 71 } 72 73 /** 74 * Connect to database 75 * @return bool 76 */ 77 public function connect( $host, $user, $pass, $port = 3306, $options = array() ) { 78 $dsn = sprintf( 'mysql:host=%1$s;port=%2$d', $host, $port ); 79 80 try { 81 $pdo_options = array(); 82 83 if ( ! empty( $options['key'] ) && ! empty( $options['cert'] ) && ! empty( $options['ca'] ) ) { 84 $pdo_options[ PDO::MYSQL_ATTR_SSL_KEY ] = $options['key']; 85 $pdo_options[ PDO::MYSQL_ATTR_SSL_CERT ] = $options['cert']; 86 $pdo_options[ PDO::MYSQL_ATTR_SSL_CA ] = $options['ca']; 87 $pdo_options[ PDO::MYSQL_ATTR_SSL_CAPATH ] = $options['ca_path']; 88 $pdo_options[ PDO::MYSQL_ATTR_SSL_CIPHER ] = $options['cipher']; 89 90 // Cleanup empty values 91 $pdo_options = array_filter( $pdo_options ); 92 } 93 94 $this->dbh = new PDO( $dsn, $user, $pass, $pdo_options ); 95 $this->dbh->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); 96 } catch ( Exception $e ) { 97 return false; 98 } 99 100 return true; 101 } 102 103 /** 104 * Select database 105 * @return void 106 */ 107 public function select( $db ) { 108 try { 109 $this->dbh->exec( sprintf( 'USE `%s`', $db ) ); 110 } catch ( Exception $e ) { 111 return false; 112 } 113 114 return true; 115 } 116 117 /** 118 * Perform a MySQL database query, using current database connection. 119 * @param string $query Database query 120 * @return int|false Number of rows affected/selected or false on error 121 */ 122 public function query( $query ) { 123 $return_val = 0; 124 125 try { 126 $this->result = $this->dbh->query( $query ); 127 } catch ( Exception $e ) { 128 if ( WP_DEBUG) { 129 global $wpdb; 130 error_log( "Error executing query: " . $e->getCode() . " - " . $e->getMessage() . " in query " . $query ); 131 } 132 return false; 133 } 134 135 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 136 $return_val = $this->result; 137 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 138 $return_val = $this->affected_rows(); 139 } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 140 $this->get_results(); 141 return count( $this->fetched_rows ); 142 } 143 144 return $return_val; 145 } 146 147 /** 148 * Get number of rows affected 149 * @return int 150 */ 151 public function affected_rows() { 152 if ( $this->result instanceof PDOStatement ) 153 return $this->result->rowCount(); 154 155 return 0; 156 } 157 158 /** 159 * Get last insert id 160 * @return int 161 */ 162 public function insert_id() { 163 return $this->dbh->lastInsertId(); 164 } 165 166 /** 167 * Get results 168 * @return array 169 */ 170 public function get_results() { 171 if ( !empty( $this->fetched_rows ) ) { 172 return $this->fetched_rows; 173 } 174 $this->fetched_rows = array(); 175 176 if ( !empty( $this->result ) && $this->result->rowCount() > 0 ) { 177 try { 178 while ( $row = $this->result->fetchObject() ) 179 $this->fetched_rows[] = $row; 180 } catch ( Exception $e ) {} 181 } 182 183 return $this->fetched_rows; 184 } 185 186 /** 187 * Load the column metadata from the last query. 188 * @return array 189 */ 190 public function load_col_info() { 191 if ( $this->col_info ) 192 return $this->col_info; 193 for ( $i = 0; $i < $this->result->columnCount() ; $i++ ) { 194 $this->col_info[ $i ] = $this->result->fetchColumn( $i ); 195 } 196 return $this->col_info; 197 } 198 199 /** 200 * The database version number. 201 * @return false|string false on failure, version number on success 202 */ 203 public function db_version() { 204 return preg_replace( '/[^0-9.].*/', '', $this->dbh->getAttribute( PDO::ATTR_SERVER_VERSION ) ); 205 } 206 207 /** 208 * Don't save any state. The db wrapper should call connect() again. 209 * @return array 210 */ 211 public function __sleep() { 212 return array(); 213 } 214 } 215 No newline at end of file -
src/wp-includes/drivers/interface-wpdb-driver.php
Property changes on: src/wp-includes/drivers/class-wpdb-driver-pdo_mysql.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property
1 <?php 2 interface wpdb_driver { 3 public function escape( $string ); 4 public function get_error_message(); 5 public function flush(); 6 public function connect( $host, $user, $pass, $port = 3306, $options = array() ); 7 public function select( $name ); 8 public function query( $query ); 9 public function load_col_info(); 10 public function db_version(); 11 public function affected_rows(); 12 public function insert_id(); 13 public function get_results(); 14 } -
src/wp-includes/wp-db.php
9 9 * @since 0.71 10 10 */ 11 11 12 require_once( dirname( __FILE__ ) . '/drivers/interface-wpdb-driver.php' ); 13 12 14 /** 13 15 * @since 0.71 14 16 */ … … 509 511 */ 510 512 public $is_mysql = null; 511 513 514 /** 515 * Pick the adapter to be used for performing the actual queries. 516 * 517 * @since 3.8.0 518 */ 519 private function set_driver() { 520 521 // Auto-pick the driver 522 if ( defined( 'WPDB_DRIVER' ) ) { 523 $driver = WPDB_DRIVER; 524 } elseif ( extension_loaded( 'pdo_mysql' ) ) { 525 $driver = 'pdo_mysql'; 526 } elseif ( extension_loaded( 'mysqli' ) ) { 527 $driver = 'mysqli'; 528 } elseif ( extension_loaded( 'mysql' ) ) { 529 $driver = 'mysql'; 530 } 531 532 // Get the new driver 533 if ( in_array( $driver, apply_filters( 'wpdb_drivers', array( 'mysql', 'mysqli', 'pdo_mysql' ) ) ) ) 534 require_once( dirname( __FILE__ ) . '/drivers/class-wpdb-driver-' . $driver . '.php' ); 535 536 $class = 'wpdb_driver_' . $driver; 537 538 if ( ! class_exists( $class ) ) { 539 wp_load_translations_early(); 540 $this->bail( sprintf( __( " 541 <h1>No database drivers found</h1>. 542 <p>WordPress requires the mysql, mysqli, or pdo_mysql extension to talk to your database.</p> 543 <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> 544 "), 'db_connect_fail' ) ); 545 } 546 547 $this->dbh = new $class(); 548 } 549 512 550 /** 513 551 * Connects to the database server and selects a database 514 552 * … … 525 563 * @param string $dbhost MySQL database host 526 564 */ 527 565 function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { 566 $this->set_driver(); 567 528 568 register_shutdown_function( array( $this, '__destruct' ) ); 529 569 530 570 if ( WP_DEBUG && WP_DEBUG_DISPLAY ) … … 636 676 $charset = $this->charset; 637 677 if ( ! isset( $collate ) ) 638 678 $collate = $this->collate; 639 if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) { 640 if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) { 641 mysql_set_charset( $charset, $dbh ); 642 } else { 643 $query = $this->prepare( 'SET NAMES %s', $charset ); 644 if ( ! empty( $collate ) ) 645 $query .= $this->prepare( ' COLLATE %s', $collate ); 646 mysql_query( $query, $dbh ); 647 } 679 if ( $this->has_cap( 'collation', $dbh ) && !empty( $charset ) ) { 680 $query = $this->prepare( 'SET NAMES %s', $charset ); 681 if ( ! empty( $collate ) ) 682 $query .= $this->prepare( ' COLLATE %s', $collate ); 683 $this->dbh->query( $query ); 648 684 } 649 685 } 650 686 … … 827 863 * @return null Always null. 828 864 */ 829 865 function select( $db, $dbh = null ) { 830 if ( is_null($dbh) ) 831 $dbh = $this->dbh; 866 $result = $dbh->select( $db ); 832 867 833 if ( ! @mysql_select_db( $db, $dbh )) {868 if ( ! $result ) { 834 869 $this->ready = false; 835 870 wp_load_translations_early(); 836 871 $this->bail( sprintf( __( '<h1>Can’t select database</h1> … … 876 911 * @return string escaped 877 912 */ 878 913 function _real_escape( $string ) { 879 if ( $this->dbh ) 880 return mysql_real_escape_string( $string, $this->dbh ); 881 882 $class = get_class( $this ); 883 _doing_it_wrong( $class, "$class must set a database connection for use with escaping.", E_USER_NOTICE ); 884 return addslashes( $string ); 914 return $this->dbh->escape( $string ); 885 915 } 886 916 887 917 /** … … 1019 1049 global $EZSQL_ERROR; 1020 1050 1021 1051 if ( !$str ) 1022 $str = mysql_error( $this->dbh);1052 $str = $this->dbh->get_error_message(); 1023 1053 $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str ); 1024 1054 1025 1055 if ( $this->suppress_errors ) … … 1116 1146 * @return void 1117 1147 */ 1118 1148 function flush() { 1149 $this->dbh->flush(); 1150 1119 1151 $this->last_result = array(); 1120 1152 $this->col_info = null; 1121 1153 $this->last_query = null; 1122 1154 $this->rows_affected = $this->num_rows = 0; 1123 1155 $this->last_error = ''; 1124 1125 if ( is_resource( $this->result ) )1126 mysql_free_result( $this->result );1127 1156 } 1128 1157 1129 1158 /** … … 1132 1161 * @since 3.0.0 1133 1162 */ 1134 1163 function db_connect() { 1135 1136 1164 $this->is_mysql = true; 1137 1165 1138 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; 1139 $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; 1140 1141 if ( WP_DEBUG ) { 1142 $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); 1143 } else { 1144 $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); 1166 if ( false !== strpos( $this->dbhost, ':' ) ) { 1167 list( $host, $port ) = explode( ':', $this->dbhost ); 1168 } else { 1169 $host = $this->dbhost; 1170 $port = 3306; 1145 1171 } 1146 1172 1147 if ( !$this->dbh ) { 1173 $options = array(); 1174 $options['key'] = defined( 'DB_SSL_KEY' ) ? DB_SSL_KEY : null; 1175 $options['cert'] = defined( 'DB_SSL_CERT' ) ? DB_SSL_CERT : null; 1176 $options['ca'] = defined( 'DB_SSL_CA' ) ? DB_SSL_CA : null; 1177 $options['ca_path'] = defined( 'DB_SSL_CA_PATH' ) ? DB_SSL_CA_PATH : null; 1178 $options['cipher'] = defined( 'DB_SSL_CIPHER' ) ? DB_SSL_CIPHER : null; 1179 1180 if ( ! $this->dbh->connect( $host, $this->dbuser, $this->dbpassword, $port, $options ) ) { 1148 1181 wp_load_translations_early(); 1149 1182 $this->bail( sprintf( __( " 1150 1183 <h1>Error establishing a database connection</h1> … … 1180 1213 function query( $query ) { 1181 1214 if ( ! $this->ready ) 1182 1215 return false; 1183 /** 1184 * Filter the database query. 1185 * 1186 * Some queries are made before the plugins have been loaded, and thus cannot be filtered with this method. 1187 * 1188 * @since 2.1.0 1189 * @param string $query Database query. 1190 */ 1216 1217 // some queries are made before the plugins have been loaded, and thus cannot be filtered with this method 1191 1218 $query = apply_filters( 'query', $query ); 1192 1219 1193 1220 $return_val = 0; … … 1202 1229 if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 1203 1230 $this->timer_start(); 1204 1231 1205 $this->result = @mysql_query( $query, $this->dbh);1232 $this->result = $this->dbh->query( $query ); 1206 1233 $this->num_queries++; 1207 1234 1208 1235 if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 1209 1236 $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() ); 1210 1237 1211 1238 // If there is an error then take note of it.. 1212 if ( $this->last_error = mysql_error( $this->dbh ) ) { 1213 // Clear insert_id on a subsequent failed insert. 1214 if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) 1215 $this->insert_id = 0; 1216 1239 if ( $this->last_error = $this->dbh->get_error_message() ) { 1217 1240 $this->print_error(); 1218 1241 return false; 1219 1242 } … … 1221 1244 if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 1222 1245 $return_val = $this->result; 1223 1246 } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 1224 $this->rows_affected = mysql_affected_rows( $this->dbh);1247 $this->rows_affected = $this->dbh->affected_rows(); 1225 1248 // Take note of the insert_id 1226 1249 if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { 1227 $this->insert_id = mysql_insert_id($this->dbh);1250 $this->insert_id = $this->dbh->insert_id(); 1228 1251 } 1229 1252 // Return number of rows affected 1230 1253 $return_val = $this->rows_affected; 1231 1254 } else { 1232 $num_rows = 0; 1233 while ( $row = @mysql_fetch_object( $this->result ) ) { 1234 $this->last_result[$num_rows] = $row; 1235 $num_rows++; 1236 } 1237 1238 // Log number of rows the query returned 1239 // and return number of rows selected 1240 $this->num_rows = $num_rows; 1241 $return_val = $num_rows; 1255 $return_val = $this->num_rows = count( $this->result ); 1242 1256 } 1243 1257 1258 $this->last_result = $this->dbh->get_results(); 1259 1244 1260 return $return_val; 1245 1261 } 1246 1262 … … 1571 1587 * @access protected 1572 1588 */ 1573 1589 protected function load_col_info() { 1574 if ( $this->col_info ) 1575 return; 1576 1577 for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) { 1578 $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); 1579 } 1590 $this->col_info = $this->dbh->load_col_info(); 1580 1591 } 1581 1592 1582 1593 /** … … 1747 1758 * @return false|string false on failure, version number on success 1748 1759 */ 1749 1760 function db_version() { 1750 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ));1761 return $this->dbh->db_version(); 1751 1762 } 1752 1763 }