Ticket #21663: 21663.patch

File 21663.patch, 21.8 KB (added by kurtpayne, 9 months ago)

Proof of concept - use a database driver system, leave wp-db mostly intact

  • wp-includes/wp-db-driver-pdo_mysql.php

     
     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 */ 
     17class 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 No newline at end of file 
  • wp-includes/wp-db-driver.interface.php

    Property changes on: wp-includes\wp-db-driver-pdo_mysql.php
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     1<?php 
     2 
     3interface 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/wp-db-driver-mysql.php

    Property changes on: wp-includes\wp-db-driver.interface.php
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     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 */ 
     17class 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                if ( WP_DEBUG ) { 
     72                        $this->dbh =  mysql_connect( $host, $user, $pass, true ); 
     73                } else { 
     74                        $this->dbh = @mysql_connect( $host, $user, $pass, true ); 
     75                } 
     76                return ( false !== $this->dbh ); 
     77        } 
     78 
     79        /** 
     80         * Select database 
     81         * @return void 
     82         */ 
     83        public function select( $db ) { 
     84                if ( WP_DEBUG ) { 
     85                         mysql_select_db( $db, $this->dbh ); 
     86                } else { 
     87                        @mysql_select_db( $db, $this->dbh ); 
     88                } 
     89        }                
     90         
     91        /** 
     92         * Perform a MySQL database query, using current database connection. 
     93         * @param string $query Database query 
     94         * @return int|false Number of rows affected/selected or false on error 
     95         */ 
     96        public function query( $query ) { 
     97                $this->result = @mysql_query( $query, $this->dbh ); 
     98                if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 
     99                        $return_val = $this->result; 
     100                } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 
     101                        $return_val = $this->affected_rows(); 
     102                } elseif ( preg_match( '/^\s*select\s/i', $query ) ) { 
     103                        return mysql_num_rows( $this->result ); 
     104                } 
     105                return true; 
     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 
  • wp-includes/wp-db-driver-mysqli.php

    Property changes on: wp-includes\wp-db-driver-mysql.php
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     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 */ 
     17class 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 No newline at end of file 
  • wp-includes/wp-db.php

    Property changes on: wp-includes\wp-db-driver-mysqli.php
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
    487487        protected $dbhost; 
    488488 
    489489        /** 
    490          * Database Handle 
     490         * Database driver object 
    491491         * 
    492          * @since 0.71 
     492         * Allow for simple, and backwards compatible, pluggable database drivers 
     493         * like PDO_mysql and mysqli to power wpdb 
     494         *  
    493495         * @access protected 
    494          * @var string 
     496         * @since 3.5.0 
     497         * @var wpdb_driver 
    495498         */ 
    496499        protected $dbh; 
    497500 
     
    519522        public $is_mysql = null; 
    520523 
    521524        /** 
     525         * Pick the right adapter and return an instance 
     526         * @static 
     527         * @since 3.5.0 
     528         * @param string $dbuser MySQL database user 
     529         * @param string $dbpassword MySQL database password 
     530         * @param string $dbname MySQL database name 
     531         * @param string $dbhost MySQL database host 
     532         * @return wpdb 
     533         */ 
     534        public function get_driver( $driver = null ) { 
     535                 
     536                // Auto-pick the driver 
     537                if ( null === $driver ) { 
     538                        if ( extension_loaded( 'mysql' ) ) { 
     539                                $driver = 'mysql'; 
     540                        } elseif ( extension_loaded( 'mysqli' ) ) { 
     541                                $driver = 'mysqli'; 
     542                        } elseif ( extension_loaded( 'pdo_mysql' ) ) { 
     543                                $driver = 'pdo_mysql'; 
     544                        } else { 
     545                                wp_load_translations_early(); 
     546                                $this->bail( sprintf( __( " 
     547                                        <h1>No database drivers found</h1>. 
     548                                        <p>WordPress requires the mysql, mysqli, or pdo_mysql extension to talk to your database.</p> 
     549                                        <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> 
     550                                "), 'db_connect_fail' ) ); 
     551                        } 
     552                } elseif ( !in_array( $driver, array( 'mysql', 'mysqli', 'pdo_mysql' ) ) ) { 
     553                        wp_load_translations_early(); 
     554                        $this->bail( sprintf( __( " 
     555                                <h1>No database drivers found</h1>. 
     556                                <p>WordPress requires the mysql, mysqli, or pdo_mysql extension to talk to your database.</p> 
     557                                <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> 
     558                        "), 'db_connect_fail' ) ); 
     559                } 
     560 
     561                // Get the new driver 
     562                require_once(dirname(dirname(__FILE__)) . '/wp-includes/wp-db-driver.interface.php'); 
     563                require_once(dirname(dirname(__FILE__)) . '/wp-includes/wp-db-driver-' . $driver . '.php'); 
     564                $class = 'wpdb_driver_' . $driver; 
     565                $this->dbh = new $class(); 
     566        } 
     567 
     568        /** 
    522569         * Connects to the database server and selects a database 
    523570         * 
    524571         * PHP5 style constructor for compatibility with PHP5. Does 
     
    534581         * @param string $dbhost MySQL database host 
    535582         */ 
    536583        function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { 
     584                 
     585                $this->get_driver(); 
     586 
    537587                register_shutdown_function( array( &$this, '__destruct' ) ); 
    538588 
    539589                if ( WP_DEBUG ) 
     
    646696                if ( !isset($collate) ) 
    647697                        $collate = $this->collate; 
    648698                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                         } 
     699                        $query = $this->prepare( 'SET NAMES %s', $charset ); 
     700                        if ( ! empty( $collate ) ) 
     701                                $query .= $this->prepare( ' COLLATE %s', $collate ); 
     702                        $this->dbh->query( $query ); 
    658703                } 
    659704        } 
    660705 
     
    837882         * @return null Always null. 
    838883         */ 
    839884        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&#8217;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                 } 
     885                $this->dbh->select( $db ); 
    856886        } 
    857887 
    858888        /** 
     
    882912         */ 
    883913        function _real_escape( $string ) { 
    884914                if ( $this->dbh && $this->real_escape ) 
    885                         return mysql_real_escape_string( $string, $this->dbh ); 
     915                        return $this->dbh->escape( $string ); 
    886916                else 
    887917                        return addslashes( $string ); 
    888918        } 
     
    10171047                global $EZSQL_ERROR; 
    10181048 
    10191049                if ( !$str ) 
    1020                         $str = mysql_error( $this->dbh ); 
     1050                        $str = $this->dbh->get_error_message(); 
    10211051                $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str ); 
    10221052 
    10231053                if ( $this->suppress_errors ) 
     
    11181148         * @return void 
    11191149         */ 
    11201150        function flush() { 
    1121                 $this->last_result = array(); 
    1122                 $this->col_info    = null; 
    1123                 $this->last_query  = null; 
    1124  
    1125                 if ( is_resource( $this->result ) ) 
    1126                         mysql_free_result( $this->result ); 
     1151                $this->dbh->flush(); 
    11271152        } 
    11281153 
    11291154        /** 
     
    11351160 
    11361161                $this->is_mysql = true; 
    11371162 
    1138                 if ( WP_DEBUG ) { 
    1139                         $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true ); 
    1140                 } else { 
    1141                         $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true ); 
     1163                $host = $this->dbhost; 
     1164                $port = 3306; 
     1165                if ( false !== strpos( $this->dbhost, ':' ) ) { 
     1166                        list( $host, $port ) = explode( ':', $this->dbhost ); 
    11421167                } 
    11431168 
    1144                 if ( !$this->dbh ) { 
     1169                if ( !$this->dbh->connect( $host, $this->dbuser, $this->dbpassword, $port ) ) { 
    11451170                        wp_load_translations_early(); 
    11461171                        $this->bail( sprintf( __( " 
    11471172<h1>Error establishing a database connection</h1> 
     
    11931218                if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 
    11941219                        $this->timer_start(); 
    11951220 
    1196                 $this->result = @mysql_query( $query, $this->dbh ); 
     1221                $result = $this->dbh->query( $query ); 
    11971222                $this->num_queries++; 
    11981223 
    11991224                if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 
    12001225                        $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() ); 
    12011226 
    12021227                // If there is an error then take note of it.. 
    1203                 if ( $this->last_error = mysql_error( $this->dbh ) ) { 
     1228                if ( $this->last_error = $this->dbh->get_error_message() ) { 
    12041229                        $this->print_error(); 
    12051230                        return false; 
    12061231                } 
     
    12081233                if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { 
    12091234                        $return_val = $this->result; 
    12101235                } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { 
    1211                         $this->rows_affected = mysql_affected_rows( $this->dbh ); 
     1236                        $this->rows_affected = $this->dbh->affected_rows(); 
    12121237                        // Take note of the insert_id 
    12131238                        if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { 
    1214                                 $this->insert_id = mysql_insert_id($this->dbh); 
     1239                                $this->insert_id = $this->dbh->insert_id(); 
    12151240                        } 
    12161241                        // Return number of rows affected 
    12171242                        $return_val = $this->rows_affected; 
    12181243                } else { 
    1219                         $num_rows = 0; 
    1220                         while ( $row = @mysql_fetch_object( $this->result ) ) { 
    1221                                 $this->last_result[$num_rows] = $row; 
    1222                                 $num_rows++; 
    1223                         } 
    1224  
    1225                         // Log number of rows the query returned 
    1226                         // and return number of rows selected 
    1227                         $this->num_rows = $num_rows; 
    1228                         $return_val     = $num_rows; 
     1244                        $this->last_result = $this->dbh->get_results(); 
     1245                        $return_val = $this->num_rows = count( $this->last_result ); 
    12291246                } 
    1230  
     1247                 
    12311248                return $return_val; 
    12321249        } 
    12331250 
     
    15571574         * @access protected 
    15581575         */ 
    15591576        protected function load_col_info() { 
    1560                 if ( $this->col_info ) 
    1561                         return; 
    1562  
    1563                 for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) { 
    1564                         $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); 
    1565                 } 
     1577                $this->col_info = $this->dbh->load_col_info(); 
    15661578        } 
    15671579 
    15681580        /** 
     
    17331745         * @return false|string false on failure, version number on success 
    17341746         */ 
    17351747        function db_version() { 
    1736                 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 
     1748                return $this->dbh->db_version(); 
    17371749        } 
    17381750}