Ticket #11644: 11644.code_cleanup_wpdb.6.patch

File 11644.code_cleanup_wpdb.6.patch, 39.8 KB (added by hakre, 3 years ago)
  • wp-db.php

     
    1212/** 
    1313 * @since 0.71 
    1414 */ 
    15 define('EZSQL_VERSION', 'WP1.25'); 
     15define( 'EZSQL_VERSION', 'WP1.25' ); 
    1616 
    1717/** 
    1818 * @since 0.71 
    1919 */ 
    20 define('OBJECT', 'OBJECT', true); 
     20define( 'OBJECT', 'OBJECT', true ); 
    2121 
    2222/** 
    2323 * @since {@internal Version Unknown}} 
    2424 */ 
    25 define('OBJECT_K', 'OBJECT_K', false); 
     25define( 'OBJECT_K', 'OBJECT_K', false ); 
    2626 
    2727/** 
    2828 * @since 0.71 
    2929 */ 
    30 define('ARRAY_A', 'ARRAY_A', false); 
     30define( 'ARRAY_A', 'ARRAY_A', false ); 
    3131 
    3232/** 
    3333 * @since 0.71 
    3434 */ 
    35 define('ARRAY_N', 'ARRAY_N', false); 
     35define( 'ARRAY_N', 'ARRAY_N', false ); 
    3636 
    3737/** 
    3838 * WordPress Database Access Abstraction Object 
     
    6565         * Whether to suppress errors during the DB bootstrapping. 
    6666         * 
    6767         * @access private 
    68          * @since {@internal Version Unknown}} 
     68         * @since 2.5 
    6969         * @var bool 
    7070         */ 
    7171        var $suppress_errors = false; 
     
    7373        /** 
    7474         * The last error during query. 
    7575         * 
    76          * @since {@internal Version Unknown}} 
     76         * @see get_last_error() 
     77         * @since 2.5 
     78         * @access private 
    7779         * @var string 
    7880         */ 
    7981        var $last_error = ''; 
     
    8890        var $num_queries = 0; 
    8991 
    9092        /** 
     93         * Amount of rows returned by last query operation 
     94         * 
     95         * @since 1.2 
     96         * @access private 
     97         * @var int 
     98         */ 
     99        var $num_rows = 0;  
     100 
     101        /** 
     102         * Number of affected rows by last query operation 
     103         * 
     104         * @since 0.71 
     105         * @access private 
     106         * @var integer 
     107         */ 
     108        var $rows_affected = 0; 
     109 
     110        /** 
    91111         * Saved result of the last query made 
    92112         * 
    93113         * @since 1.2.0 
     
    97117        var $last_query; 
    98118 
    99119        /** 
     120         * Saved resultset of the last query made 
     121         * 
     122         * @since {@internal Version Unknown} 
     123         * @access private 
     124         * @var array (null if unintialized) 
     125         */ 
     126        var $last_result; 
     127 
     128        /** 
    100129         * Saved info on the table column 
    101130         * 
    102131         * @since 1.2.0 
     
    135164         * @var bool 
    136165         */ 
    137166        var $ready = false; 
     167 
     168        /** 
     169         * {@internal Missing Description}} 
     170         * 
     171         * @since 3.0 
     172         * @access private 
     173         * @var unknown_type 
     174         */ 
    138175        var $blogid = 0; 
     176 
     177        /** 
     178         * {@internal Missing Description}} 
     179         * 
     180         * @since 3.0 
     181         * @access private 
     182         * @var unknown_type 
     183         */ 
    139184        var $siteid = 0; 
    140185 
    141186        /** 
     
    250295 
    251296        /** 
    252297         * List of deprecated WordPress tables 
     298         *  
     299         * - categories, post2cat and link2cat are deprecated  
     300         *   since 2.3.0 / db version >= 5539. 
    253301         * 
    254302         * @since 2.9.0 
    255303         * @access private 
     
    406454         * @param string $dbname MySQL database name 
    407455         * @param string $dbhost MySQL database host 
    408456         */ 
    409         function wpdb($dbuser, $dbpassword, $dbname, $dbhost) { 
     457        function wpdb( $dbuser, $dbpassword, $dbname, $dbhost ) { 
    410458                if( defined( 'WP_USE_MULTIPLE_DB' ) && WP_USE_MULTIPLE_DB ) 
    411459                        $this->db_connect(); 
    412                 return $this->__construct($dbuser, $dbpassword, $dbname, $dbhost); 
     460                return $this->__construct( $dbuser, $dbpassword, $dbname, $dbhost ); 
    413461        } 
    414462 
    415463        /** 
     
    426474         * @param string $dbname MySQL database name 
    427475         * @param string $dbhost MySQL database host 
    428476         */ 
    429         function __construct($dbuser, $dbpassword, $dbname, $dbhost) { 
    430                 register_shutdown_function(array(&$this, "__destruct")); 
     477        function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { 
     478                register_shutdown_function( array( &$this, '__destruct' ) ); # prevents the object from unloading 
    431479 
    432480                if ( WP_DEBUG ) 
    433481                        $this->show_errors(); 
     
    442490                        $this->collate = DB_COLLATE; 
    443491                } 
    444492 
    445                 if ( defined('DB_CHARSET') ) 
     493                if ( defined( 'DB_CHARSET' ) ) 
    446494                        $this->charset = DB_CHARSET; 
    447495 
    448496                $this->dbuser = $dbuser; 
    449497 
    450                 $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true); 
    451                 if (!$this->dbh) { 
    452                         $this->bail(sprintf(/*WP_I18N_DB_CONN_ERROR*/" 
     498                $this->dbh = @mysql_connect( $dbhost, $dbuser, $dbpassword, true ); 
     499                if ( !$this->dbh ) { 
     500                        $this->bail( sprintf( /*WP_I18N_DB_CONN_ERROR*/" 
    453501<h1>Error establishing a database connection</h1> 
    454502<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>%s</code>. This could mean your host's database server is down.</p> 
    455503<ul> 
     
    458506        <li>Are you sure that the database server is running?</li> 
    459507</ul> 
    460508<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> 
    461 "/*/WP_I18N_DB_CONN_ERROR*/, $dbhost), 'db_connect_fail'); 
     509"/*/WP_I18N_DB_CONN_ERROR*/, $dbhost ), 'db_connect_fail' ); 
    462510                        return; 
    463511                } 
    464512 
    465513                $this->ready = true; 
    466514 
    467                 if ( $this->has_cap( 'collation' ) && !empty($this->charset) ) { 
    468                         if ( function_exists('mysql_set_charset') ) { 
    469                                 mysql_set_charset($this->charset, $this->dbh); 
     515                if ( $this->has_cap( 'collation' ) && !empty( $this->charset ) ) { 
     516                        if ( function_exists( 'mysql_set_charset' ) ) { 
     517                                mysql_set_charset( $this->charset, $this->dbh ); 
    470518                                $this->real_escape = true; 
    471519                        } else { 
    472                                 $collation_query = "SET NAMES '{$this->charset}'"; 
    473                                 if ( !empty($this->collate) ) 
    474                                         $collation_query .= " COLLATE '{$this->collate}'"; 
    475                                 $this->query($collation_query); 
     520                                $query = $this->prepare( 'SET NAMES %s', $this->charset ); 
     521                                if ( !empty( $this->collate ) ) 
     522                                        $query .= $this->prepare( ' COLLATE %s', $this->collate ); 
     523                                $this->query( $query ); 
    476524                        } 
    477525                } 
    478526 
    479                 $this->select($dbname, $this->dbh); 
     527                $this->select( $dbname, $this->dbh ); 
    480528        } 
    481529 
    482530        /** 
    483531         * PHP5 style destructor and will run when database object is destroyed. 
    484532         * 
     533         * 
     534         *   Please see {@link __construct() class constructor} and the  
     535         *   {@link register_shutdown_function() register_shutdown_function()}. for 
     536         *   more details. 
     537         * 
     538         * @link http://www.php.net/__destruct 
     539         * @link http://www.php.net/register_shutdown_function  
     540         * 
    485541         * @since 2.0.8 
    486542         * 
    487          * @return bool Always true 
     543         * @return bool true 
    488544         */ 
    489545        function __destruct() { 
    490546                return true; 
     
    503559         */ 
    504560        function set_prefix( $prefix ) { 
    505561 
    506                 if ( preg_match('|[^a-z0-9_]|i', $prefix) ) 
     562                if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) 
    507563                        return new WP_Error('invalid_db_prefix', /*WP_I18N_DB_BAD_PREFIX*/'Invalid database prefix'/*/WP_I18N_DB_BAD_PREFIX*/); 
     564                         
     565                $old_prefix = is_multisite() ? '' : $prefix; 
    508566 
    509                 if ( is_multisite() ) 
    510                         $old_prefix = ''; 
    511                 else 
    512                         $old_prefix = $prefix; 
    513  
    514567                if ( isset( $this->base_prefix ) ) 
    515568                        $old_prefix = $this->base_prefix; 
     569 
    516570                $this->base_prefix = $prefix; 
     571 
    517572                foreach ( $this->tables( 'global' ) as $table ) 
    518573                        $this->$table = $prefix . $table; 
    519574 
    520                 if ( defined('VHOST') && empty( $this->blogid ) ) 
     575                if ( defined( 'VHOST' ) && empty( $this->blogid ) ) 
    521576                        return $old_prefix; 
    522577 
    523578                $this->prefix = $this->get_blog_prefix( $this->blogid ); 
    524579 
    525                 foreach ( (array) $this->tables( 'blog' ) as $table ) 
     580                foreach ( $this->tables( array('blog', 'old' ) ) as $table ) 
    526581                        $this->$table = $this->prefix . $table; 
    527582 
    528                 foreach ( (array) $this->tables( 'old' ) as $table ) 
    529                         $this->$table = $this->prefix . $table; 
    530  
    531                 if ( defined('CUSTOM_USER_TABLE') ) 
     583                if ( defined( 'CUSTOM_USER_TABLE' ) ) 
    532584                        $this->users = CUSTOM_USER_TABLE; 
    533585 
    534                 if ( defined('CUSTOM_USER_META_TABLE') ) 
     586                if ( defined( 'CUSTOM_USER_META_TABLE' ) ) 
    535587                        $this->usermeta = CUSTOM_USER_META_TABLE; 
    536588 
    537589                return $old_prefix; 
    538590        } 
    539591 
    540         function set_blog_id($blog_id, $site_id = '') { 
     592        /** 
     593         * blog id setter 
     594         *  
     595         * {@internal Missing Description}} 
     596         * 
     597         * @since 3.0 
     598         * @access public 
     599         * @param string $blog_id 
     600         * @param string $site_id (optional) 
     601         * @return string previous blog id 
     602         */      
     603        function set_blog_id( $blog_id, $site_id = '' ) { 
    541604                if ( !empty($site_id) ) 
    542605                        $this->siteid = $site_id; 
    543606 
    544                 $old_blog_id = $this->blogid; 
     607                $old_blog_id  = $this->blogid; 
    545608                $this->blogid = $blog_id; 
    546609 
    547610                $this->prefix = $this->get_blog_prefix( $this->blogid ); 
    548611 
    549                 foreach ( $this->tables( 'blog' ) as $table ) 
     612                foreach ( $this->tables( array('blog', 'old') ) as $table ) 
    550613                        $this->$table = $this->prefix . $table; 
    551614 
    552                 foreach ( $this->tables( 'old' ) as $table ) 
    553                         $this->$table = $this->prefix . $table; 
    554  
    555615                return $old_blog_id; 
    556616        } 
    557617 
     618        /** 
     619         * blog prefix getter 
     620         *  
     621         * {@internal Missing Description}} 
     622         *  
     623         * @param string $blog_id (optional) 
     624         * @return unknown_type 
     625         */ 
    558626        function get_blog_prefix( $blog_id = '' ) { 
    559627                if ( is_multisite() && $blog_id ) { 
    560628                        if ( defined('MULTISITE') && ( $blog_id == 0 || $blog_id == 1 ) ) 
     
    569637        /** 
    570638         * Returns an array of WordPress tables. 
    571639         * 
     640         * Scope / Table identifiers: 
     641         *  
     642         *   - 'all' ........ global and blog tables. 
     643         *   - 'global' ..... global tables 
     644         *   - 'blog' ....... blog tables 
     645         *   - 'old tables' . old (depreacted) tables 
     646         *    
     647         * NOTE: This function does not reflect CUSTOM_USER_TABLE   
     648         *       and CUSTOM_USER_META_TABLE and will return 
     649         *       the standard table names (users, usermeta) instead. 
     650         * 
     651         * FIXME all does not return global and blog, it resturns more on 
     652         *       more on multisite. fix global? merge in all? 
     653         * 
     654         * @access public 
    572655         * @since 3.0.0 
    573          * @uses wpdb::tables 
    574          * @uses wpdb::old_tables 
    575          * @uses wpdb::global_tables 
     656         * @uses wpdb::$tables 
     657         * @uses wpdb::$old_tables 
     658         * @uses wpdb::$global_tables 
     659         * @uses wpdb::$ms_tables 
    576660         * @uses is_multisite() 
    577661         * 
    578          * @param string $scope Can be all, global, blog, or old tables. Default all. 
    579          *      All returns all global tables and the blog tables for the queried blog. 
    580          * @param bool $prefix Whether to include the blog prefix. Default false. 
    581          * @param int $blog_id The blog_id to prefix. Defaults to main blog. 
     662         * @param string|array $scope (optional) Scope, Default 'all'. You can pass multiple scopes per array 
     663         * @param bool $prefix (optional) Whether to include the blog prefix. Default FALSE. 
     664         * @param int $blog_id (optional) The blog_id to prefix. 
    582665         * @return array Table names. 
    583666         */ 
    584         function tables( $scope = 'all', $prefix = false, $blog_id = 0 ) { 
    585                 switch ( $scope ) { 
    586                         case 'old' : 
    587                                 $tables = $this->old_tables; 
    588                                 break; 
    589                         case 'blog' : 
    590                                 $tables = $this->tables; 
    591                                 break; 
    592                         case 'global' : 
    593                                 $tables = array_merge( $this->global_tables, $this->ms_tables ); 
    594                                 break; 
    595                         case 'all' : 
    596                                 $tables = array_merge( $this->global_tables, $this->tables ); 
    597                                 if ( is_multisite() ) 
    598                                         $tables = array_merge( $tables, $this->ms_tables ); 
    599                                 break; 
     667        function tables( $scope = 'all', $prefix = false, $blog_id = '' ) { 
     668                 
     669                if ( is_array( $scope ) ) { 
     670                        $tables = array(); 
     671                        foreach ( $scope as $each )  
     672                                $tables = array_merge( $tables, $this->tables( $each ) ); 
     673                } else {         
     674                        switch ( $scope ) { 
     675                                case 'old' : 
     676                                        $tables = $this->old_tables; 
     677                                        break; 
     678                                case 'blog' : 
     679                                        $tables = $this->tables; 
     680                                        break; 
     681                                case 'global' : 
     682                                        $tables = array_merge( $this->global_tables, $this->ms_tables ); 
     683                                        break; 
     684                                case 'all' : 
     685                                        $tables = array_merge( $this->global_tables, $this->tables ); 
     686                                        if ( is_multisite() ) 
     687                                                $tables = array_merge( $tables, $this->ms_tables ); 
     688                                        break; 
     689                        } 
    600690                } 
    601691 
    602                 if ( $prefix ) { 
     692                if ( count( $tables ) && $prefix ) { 
    603693                        $prefix = $this->get_blog_prefix( $blog_id ); 
    604                         foreach ( $tables as $k => $table ) { 
     694                        foreach ( $tables as $k => $table ) 
    605695                                $tables[$k] = $prefix . $table; 
    606                         } 
    607696                } 
    608697 
    609698                return $tables; 
     
    620709         * @param string $db MySQL database name 
    621710         * @return null Always null. 
    622711         */ 
    623         function select($db, &$dbh) { 
    624                 if (!@mysql_select_db($db, $dbh)) { 
     712        function select( $db, &$dbh ) { 
     713                if ( !@mysql_select_db( $db, $dbh ) ) { 
    625714                        $this->ready = false; 
    626                         $this->bail(sprintf(/*WP_I18N_DB_SELECT_DB*/' 
     715                        $this->bail( sprintf( /*WP_I18N_DB_SELECT_DB*/' 
    627716<h1>Can&#8217;t select database</h1> 
    628717<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> 
    629718<ul> 
     
    631720<li>Does the user <code>%2$s</code> have permission to use the <code>%1$s</code> database?</li> 
    632721<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> 
    633722</ul> 
    634 <p>If you don\'t know how to setup 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>'/*/WP_I18N_DB_SELECT_DB*/, $db, $this->dbuser), 'db_select_fail'); 
     723<p>If you don\'t know how to setup 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>'/*/WP_I18N_DB_SELECT_DB*/, $db, $this->dbuser ), 'db_select_fail' ); 
    635724                        return; 
    636725                } 
    637726        } 
    638727 
    639         function _weak_escape($string) { 
    640                 return addslashes($string); 
     728        /** 
     729         * weak escape 
     730         * 
     731         * an alias to addslashes() 
     732         * 
     733         * @see addslashes() 
     734         * 
     735         * @since {@internal Version Unknown}} 
     736         * @access private 
     737         * @param string $string 
     738         * @return string 
     739         */ 
     740        function _weak_escape( $string ) { 
     741                return addslashes( $string ); 
    641742        } 
    642743 
    643         function _real_escape($string) { 
     744        /** 
     745         * real escape 
     746         * 
     747         * escape via mysql_real_escape_string() or addslashes()   
     748         * 
     749         * @since  2.8 
     750         * @access private 
     751         * 
     752         * @param  string $string to escape 
     753         * @return string escaped 
     754         */ 
     755        function _real_escape( $string ) { 
    644756                if ( $this->dbh && $this->real_escape ) 
    645757                        return mysql_real_escape_string( $string, $this->dbh ); 
    646758                else 
    647759                        return addslashes( $string ); 
    648760        } 
    649761 
    650         function _escape($data) { 
    651                 if ( is_array($data) ) { 
     762        /** 
     763         * escape 
     764         * 
     765         * escape data, uses {@see _real_escape()} and works  
     766         * on arrays as well. 
     767         * 
     768         * @since  2.8 
     769         * @access private 
     770         *  
     771         * @param  string|array $data to escape 
     772         * @return string|array escaped 
     773         */ 
     774        function _escape( $data ) { 
     775                if ( is_array( $data ) ) { 
    652776                        foreach ( (array) $data as $k => $v ) { 
    653777                                if ( is_array($v) ) 
    654778                                        $data[$k] = $this->_escape( $v ); 
     
    667791         * 
    668792         * @since 0.71 
    669793         * 
    670          * @param string|array $data 
    671          * @return string query safe string 
     794         * @param  string|array $data to escape 
     795         * @return string|array escaped as query safe string 
    672796         */ 
    673         function escape($data) { 
    674                 if ( is_array($data) ) { 
     797        function escape( $data ) { 
     798                if ( is_array( $data ) ) { 
    675799                        foreach ( (array) $data as $k => $v ) { 
    676                                 if ( is_array($v) ) 
     800                                if ( is_array( $v ) ) 
    677801                                        $data[$k] = $this->escape( $v ); 
    678802                                else 
    679803                                        $data[$k] = $this->_weak_escape( $v ); 
     
    690814         * 
    691815         * @since 2.3.0 
    692816         * 
    693          * @param string $s 
     817         * @param  string $string to escape 
     818         * @return void 
    694819         */ 
    695         function escape_by_ref(&$string) { 
     820        function escape_by_ref( &$string ) { 
    696821                $string = $this->_real_escape( $string ); 
    697822        } 
    698823 
    699824        /** 
    700825         * Prepares a SQL query for safe execution.  Uses sprintf()-like syntax. 
    701826         * 
     827         * The following directives can be used in the query format string:  
     828         * 
     829         *   %d (decimal number)   
     830         *   %s (string) 
     831         *   %% (literal percentage sign - no argument needed)  
     832         * 
     833         * Both %d and %s are to be left unquoted in the query string and    
     834         * they need an argument passed for them.  
     835         * Literals (%) as parts of the query must be properly written  
     836         * as %%.  
     837         *   
    702838         * This function only supports a small subset of the sprintf syntax; it only supports %d (decimal number), %s (string). 
    703839         * Does not support sign, padding, alignment, width or precision specifiers. 
    704840         * Does not support argument numbering/swapping. 
     
    709845         * 
    710846         * <code> 
    711847         * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", "foo", 1337 ) 
     848         * wpdb::prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' ); 
    712849         * </code> 
    713850         * 
    714851         * @link http://php.net/sprintf Description of syntax. 
    715852         * @since 2.3.0 
    716853         * 
    717854         * @param string $query Query statement with sprintf()-like placeholders 
    718          * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called like {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. 
     855         * @param mixed $args The array of variables to substitute into the query's placeholders if being called like {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. 
    719856         * @param mixed $args,... further variables to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. 
    720          * @return null|string Sanitized query string 
     857         * @return null|false|string Sanitized query string, null if there is no query, false if there is an error and string if there was something to prepare 
    721858         */ 
    722         function prepare($query = null) { // ( $query, *$args ) 
     859        function prepare( $query = null ) { // ( $query, *$args ) 
    723860                if ( is_null( $query ) ) 
    724861                        return; 
     862 
    725863                $args = func_get_args(); 
    726                 array_shift($args); 
    727                 // If args were passed as an array (as in vsprintf), move them up 
    728                 if ( isset($args[0]) && is_array($args[0]) ) 
    729                         $args = $args[0]; 
    730                 $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it 
    731                 $query = str_replace('"%s"', '%s', $query); // doublequote unquoting 
    732                 $query = str_replace('%s', "'%s'", $query); // quote the strings 
    733                 array_walk($args, array(&$this, 'escape_by_ref')); 
    734                 return @vsprintf($query, $args); 
     864                array_shift( $args ); 
     865                if ( isset( $args[0] ) && is_array( $args[0] ) ) 
     866                        $args = $args[0]; # re-assign args passed as array like in vsprintf 
     867 
     868                $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it 
     869                $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting 
     870                $query = str_replace( '%s', "'%s'", $query ); // quote the strings 
     871                array_walk( $args, array( &$this, 'escape_by_ref' ) ); 
     872                return @vsprintf( $query, $args ); 
    735873        } 
    736874 
    737875        /** 
     
    743881         * @param string $str The error to display 
    744882         * @return bool False if the showing of errors is disabled. 
    745883         */ 
    746         function print_error($str = '') { 
     884        function print_error( $str = '' ) { 
    747885                global $EZSQL_ERROR; 
    748886 
    749                 if (!$str) $str = mysql_error($this->dbh); 
    750                 $EZSQL_ERROR[] = array ('query' => $this->last_query, 'error_str' => $str); 
     887                if ( !$str ) $str = mysql_error( $this->dbh ); 
     888                $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str ); 
    751889 
    752890                if ( $this->suppress_errors ) 
    753891                        return false; 
     
    757895                else 
    758896                        $error_str = sprintf(/*WP_I18N_DB_QUERY_ERROR*/'WordPress database error %1$s for query %2$s'/*/WP_I18N_DB_QUERY_ERROR*/, $str, $this->last_query); 
    759897 
    760                 $log_error = true; 
    761                 if ( ! function_exists('error_log') ) 
    762                         $log_error = false; 
     898                if ( function_exists( 'error_log' ) 
     899                     && !( $log_file = @ini_get( 'error_log' ) ) 
     900                     && ( 'syslog' != $log_file ) 
     901                     && @is_writable( $log_file ) )  
     902                    @error_log( $error_str ); 
    763903 
    764                 $log_file = @ini_get('error_log'); 
    765                 if ( !empty($log_file) && ('syslog' != $log_file) && !@is_writable($log_file) ) 
    766                         $log_error = false; 
    767  
    768                 if ( $log_error ) 
    769                         @error_log($error_str, 0); 
    770  
    771904                // Is error output turned on or not.. 
    772905                if ( !$this->show_errors ) 
    773906                        return false; 
     
    778911                        if ( defined( 'ERRORLOGFILE' ) ) 
    779912                                error_log( $msg, 3, ERRORLOGFILE ); 
    780913                        if ( defined( 'DIEONDBERROR' ) ) 
    781                                 die( $msg ); 
     914                                wp_die( $msg ); 
    782915                } else { 
    783                         $str = htmlspecialchars($str, ENT_QUOTES); 
    784                         $query = htmlspecialchars($this->last_query, ENT_QUOTES); 
     916                        $str   = htmlspecialchars( $str, ENT_QUOTES ); 
     917                        $query = htmlspecialchars( $this->last_query, ENT_QUOTES ); 
    785918 
    786919                        print "<div id='error'> 
    787920                        <p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br /> 
     
    799932         * errors. 
    800933         * 
    801934         * @since 0.71 
     935         * @see hide_errors() 
    802936         * 
    803937         * @param bool $show Whether to show or hide errors 
    804938         * @return bool Old value for showing errors. 
     
    812946        /** 
    813947         * Disables showing of database errors. 
    814948         * 
     949         * By default database errors are not shown. 
     950         * 
    815951         * @since 0.71 
     952         * @see show_errors() 
    816953         * 
    817954         * @return bool Whether showing of errors was active or not 
    818955         */ 
     
    825962        /** 
    826963         * Whether to suppress database errors. 
    827964         * 
    828          * @param unknown_type $suppress 
    829          * @return unknown 
     965         * By default database errors are suppressed, with a simple 
     966         * call to this function they can be enabled. 
     967         * 
     968         * @since 2.5 
     969         * @see hide_errors() 
     970         * @param bool $suppress (optional) new value, defaults to true 
     971         * @return bool old suppress errors value 
    830972         */ 
    831973        function suppress_errors( $suppress = true ) { 
    832974                $errors = $this->suppress_errors; 
    833                 $this->suppress_errors = $suppress; 
     975                $this->suppress_errors = (bool) $suppress; 
    834976                return $errors; 
    835977        } 
    836978 
     
    838980         * Kill cached query results. 
    839981         * 
    840982         * @since 0.71 
     983         * 
     984         * @return void 
    841985         */ 
    842986        function flush() { 
    843987                $this->last_result = array(); 
    844                 $this->col_info = null; 
    845                 $this->last_query = null; 
     988                $this->col_info    = null; 
     989                $this->last_query  = null; 
    846990        } 
    847991 
    848992        function db_connect( $query = "SELECT" ) { 
     
    8651009                } 
    8661010 
    8671011                $dbhname = "dbh" . $action; 
    868                 $this->$dbhname = @mysql_connect( $details[ 'db_host' ], $details[ 'db_user' ], $details[ 'db_password' ] ); 
     1012                $this->$dbhname = @mysql_connect( $details[ 'db_host' ], $details[ 'db_user' ], $details[ 'db_password' ] );             
    8691013                if (!$this->$dbhname ) { 
    870                         $this->bail(" 
     1014                        $this->bail( sprintf( /*WP_I18N_DB_CONNECT_DB*/' 
    8711015<h1>Error establishing a database connection</h1> 
    872 <p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>{$details['db_host']}</code>. This could mean your host's database server is down.</p> 
     1016<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can\'t contact the database server at <code>%s</code>. This could mean your host\'s database server is down.</p> 
    8731017<ul> 
    8741018        <li>Are you sure you have the correct username and password?</li> 
    8751019        <li>Are you sure that you have typed the correct hostname?</li> 
    8761020        <li>Are you sure that the database server is running?</li> 
    8771021</ul> 
    878 <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> 
    879 "); 
     1022<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>'/*/WP_I18N_DB_CONNECT_DB*/, $dbhost) ); 
    8801023                } 
    8811024                $this->select( $details[ 'db_name' ], $this->$dbhname ); 
    8821025        } 
     
    8881031         * 
    8891032         * @since 0.71 
    8901033         * 
    891          * @param string $query 
     1034         * @param string $query database query 
    8921035         * @return int|false Number of rows affected/selected or false on error 
    8931036         */ 
    894         function query($query) { 
     1037        function query( $query ) { 
    8951038                if ( ! $this->ready ) 
    8961039                        return false; 
    8971040 
    898                 // filter the query, if filters are available 
    899                 // NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method 
    900                 if ( function_exists('apply_filters') ) 
    901                         $query = apply_filters('query', $query); 
     1041                if ( function_exists( 'apply_filters' ) ) 
     1042                        $query = apply_filters( 'query', $query ); 
    9021043 
    903                 // initialise return 
     1044                // init return values and object's state 
    9041045                $return_val = 0; 
    9051046                $this->flush(); 
    9061047 
     
    9101051                // Keep track of the last query for debug.. 
    9111052                $this->last_query = $query; 
    9121053 
    913                 // Perform the query via std mysql_query function.. 
    914                 if ( defined('SAVEQUERIES') && SAVEQUERIES ) 
     1054                if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 
    9151055                        $this->timer_start(); 
    9161056 
    9171057                // use $this->dbh for read ops, and $this->dbhwrite for write ops 
     
    9391079                        $this->last_db_used = "other/read"; 
    9401080                } 
    9411081 
    942                 $this->result = @mysql_query($query, $dbh); 
    943                 ++$this->num_queries; 
     1082                // Perform the query via std mysql_query function.. 
     1083                $this->result = @mysql_query( $query, $dbh ); 
     1084                $this->num_queries++; 
    9441085 
    9451086                if ( defined('SAVEQUERIES') && SAVEQUERIES ) 
    9461087                        $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() ); 
    9471088 
    9481089                // If there is an error then take note of it.. 
    949                 if ( $this->last_error = mysql_error($dbh) ) { 
     1090                if ( $this->last_error = mysql_error( $dbh ) ) { 
    9501091                        $this->print_error(); 
    9511092                        return false; 
    9521093                } 
    9531094 
    954                 if ( preg_match("/^\\s*(insert|delete|update|replace|alter) /i",$query) ) { 
    955                         $this->rows_affected = mysql_affected_rows($dbh); 
     1095                if ( preg_match( "/^\\s*(insert|delete|update|replace|alter) /i", $query ) ) { 
     1096                        $this->rows_affected = mysql_affected_rows( $dbh ); 
    9561097                        // Take note of the insert_id 
    957                         if ( preg_match("/^\\s*(insert|replace) /i",$query) ) { 
     1098                        if ( preg_match( "/^\\s*(insert|replace) /i", $query ) ) { 
    9581099                                $this->insert_id = mysql_insert_id($dbh); 
    9591100                        } 
    9601101                        // Return number of rows affected 
    9611102                        $return_val = $this->rows_affected; 
    9621103                } else { 
    9631104                        $i = 0; 
    964                         while ($i < @mysql_num_fields($this->result)) { 
    965                                 $this->col_info[$i] = @mysql_fetch_field($this->result); 
     1105                        while ( $i < @mysql_num_fields( $this->result ) ) { 
     1106                                $this->col_info[$i] = @mysql_fetch_field( $this->result ); 
    9661107                                $i++; 
    9671108                        } 
    9681109                        $num_rows = 0; 
    969                         while ( $row = @mysql_fetch_object($this->result) ) { 
     1110                        while ( $row = @mysql_fetch_object( $this->result ) ) { 
    9701111                                $this->last_result[$num_rows] = $row; 
    9711112                                $num_rows++; 
    9721113                        } 
    9731114 
    974                         @mysql_free_result($this->result); 
     1115                        @mysql_free_result( $this->result ); 
    9751116 
    9761117                        // Log number of rows the query returned 
     1118                        // and Return number of rows selected 
    9771119                        $this->num_rows = $num_rows; 
    978  
    979                         // Return number of rows selected 
    980                         $return_val = $this->num_rows; 
     1120                        $return_val     = $num_rows; 
    9811121                } 
    9821122 
    9831123                return $return_val; 
     
    9871127         * Insert a row into a table. 
    9881128         * 
    9891129         * <code> 
     1130         * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ) ) 
    9901131         * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) 
    9911132         * </code> 
    9921133         * 
     
    9981139         * @param array|string $format (optional) An array of formats to be mapped to each of the value in $data.  If string, that format will be used for all of the values in $data.  A format is one of '%d', '%s' (decimal number, string).  If omitted, all values in $data will be treated as strings. 
    9991140         * @return int|false The number of rows inserted, or false on error. 
    10001141         */ 
    1001         function insert($table, $data, $format = null) { 
     1142        function insert( $table, $data, $format = null ) { 
    10021143                $formats = $format = (array) $format; 
    1003                 $fields = array_keys($data); 
     1144                $fields = array_keys( $data ); 
    10041145                $formatted_fields = array(); 
    10051146                foreach ( $fields as $field ) { 
    1006                         if ( !empty($format) ) 
    1007                                 $form = ( $form = array_shift($formats) ) ? $form : $format[0]; 
    1008                         elseif ( isset($this->field_types[$field]) ) 
     1147                        if ( !empty( $format ) ) 
     1148                                $form = ( $form = array_shift( $formats ) ) ? $form : $format[0]; 
     1149                        elseif ( isset( $this->field_types[$field] ) ) 
    10091150                                $form = $this->field_types[$field]; 
    10101151                        else 
    10111152                                $form = '%s'; 
    10121153                        $formatted_fields[] = $form; 
    10131154                } 
    10141155                $sql = "INSERT INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES ('" . implode( "','", $formatted_fields ) . "')"; 
    1015                 return $this->query( $this->prepare( $sql, $data) ); 
     1156                return $this->query( $this->prepare( $sql, $data ) ); 
    10161157        } 
    10171158 
    10181159 
     
    10201161         * Update a row in the table 
    10211162         * 
    10221163         * <code> 
     1164         * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ) ) 
    10231165         * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) ) 
    10241166         * </code> 
    10251167         * 
     
    10331175         * @param array|string $format_where (optional) An array of formats to be mapped to each of the values in $where.  If string, that format will be used for all of  the items in $where.  A format is one of '%d', '%s' (decimal number, string).  If omitted, all values in $where will be treated as strings. 
    10341176         * @return int|false The number of rows updated, or false on error. 
    10351177         */ 
    1036         function update($table, $data, $where, $format = null, $where_format = null) { 
    1037                 if ( !is_array( $where ) ) 
     1178        function update( $table, $data, $where, $format = null, $where_format = null ) { 
     1179                if ( !is_array( $data ) || !is_array( $where ) ) 
    10381180                        return false; 
    10391181 
    10401182                $formats = $format = (array) $format; 
    10411183                $bits = $wheres = array(); 
    1042                 foreach ( (array) array_keys($data) as $field ) { 
    1043                         if ( !empty($format) ) 
    1044                                 $form = ( $form = array_shift($formats) ) ? $form : $format[0]; 
     1184                foreach ( (array) array_keys( $data ) as $field ) { 
     1185                        if ( !empty( $format ) ) 
     1186                                $form = ( $form = array_shift( $formats ) ) ? $form : $format[0]; 
    10451187                        elseif ( isset($this->field_types[$field]) ) 
    10461188                                $form = $this->field_types[$field]; 
    10471189                        else 
     
    10501192                } 
    10511193 
    10521194                $where_formats = $where_format = (array) $where_format; 
    1053                 foreach ( (array) array_keys($where) as $field ) { 
    1054                         if ( !empty($where_format) ) 
    1055                                 $form = ( $form = array_shift($where_formats) ) ? $form : $where_format[0]; 
    1056                         elseif ( isset($this->field_types[$field]) ) 
     1195                foreach ( (array) array_keys( $where ) as $field ) { 
     1196                        if ( !empty( $where_format ) ) 
     1197                                $form = ( $form = array_shift( $where_formats ) ) ? $form : $where_format[0]; 
     1198                        elseif ( isset( $this->field_types[$field] ) ) 
    10571199                                $form = $this->field_types[$field]; 
    10581200                        else 
    10591201                                $form = '%s'; 
     
    10611203                } 
    10621204 
    10631205                $sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres ); 
    1064                 return $this->query( $this->prepare( $sql, array_merge(array_values($data), array_values($where))) ); 
     1206                return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) ); 
    10651207        } 
    10661208 
    10671209        /** 
     
    10731215         * 
    10741216         * @since 0.71 
    10751217         * 
    1076          * @param string|null $query SQL query.  If null, use the result from the previous query. 
     1218         * @param string|null $query (optional) SQL query. Defaults to NULL, use the result from the previous query. 
    10771219         * @param int $x (optional) Column of value to return.  Indexed from 0. 
    10781220         * @param int $y (optional) Row of value to return.  Indexed from 0. 
    1079          * @return string Database query result 
     1221         * @return string|null Database query result on success (as string), NULL if a value on failure 
    10801222         */ 
    1081         function get_var($query=null, $x = 0, $y = 0) { 
    1082                 $this->func_call = "\$db->get_var(\"$query\",$x,$y)"; 
     1223        function get_var( $query = null, $x = 0, $y = 0 ) { 
     1224                $this->func_call = "\$db->get_var(\"$query\", $x, $y)"; 
    10831225                if ( $query ) 
    1084                         $this->query($query); 
     1226                        $this->query( $query ); 
    10851227 
    10861228                // Extract var out of cached results based x,y vals 
    10871229                if ( !empty( $this->last_result[$y] ) ) { 
    1088                         $values = array_values(get_object_vars($this->last_result[$y])); 
     1230                        $values = array_values( get_object_vars( $this->last_result[$y] ) ); 
    10891231                } 
    10901232 
    10911233                // If there is a value return it else return null 
    1092                 return (isset($values[$x]) && $values[$x]!=='') ? $values[$x] : null; 
     1234                return ( isset( $values[$x] ) && $values[$x] !== '' ) ? $values[$x] : null; 
    10931235        } 
    10941236 
    10951237        /** 
     
    11021244         * @param string|null $query SQL query. 
    11031245         * @param string $output (optional) one of ARRAY_A | ARRAY_N | OBJECT constants.  Return an associative array (column => value, ...), a numerically indexed array (0 => value, ...) or an object ( ->column = value ), respectively. 
    11041246         * @param int $y (optional) Row to return.  Indexed from 0. 
    1105          * @return mixed Database query result in format specifed by $output 
     1247         * @return mixed Database query result in format specifed by $output or NULL 
     1248         * @return void 
    11061249         */ 
    1107         function get_row($query = null, $output = OBJECT, $y = 0) { 
     1250        function get_row( $query = null, $output = OBJECT, $y = 0 ) { 
    11081251                $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; 
    11091252                if ( $query ) 
    1110                         $this->query($query); 
     1253                        $this->query( $query ); 
    11111254                else 
    11121255                        return null; 
    11131256 
    1114                 if ( !isset($this->last_result[$y]) ) 
     1257                if ( !isset( $this->last_result[$y] ) ) 
    11151258                        return null; 
    11161259 
    11171260                if ( $output == OBJECT ) { 
    11181261                        return $this->last_result[$y] ? $this->last_result[$y] : null; 
    11191262                } elseif ( $output == ARRAY_A ) { 
    1120                         return $this->last_result[$y] ? get_object_vars($this->last_result[$y]) : null; 
     1263                        return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null; 
    11211264                } elseif ( $output == ARRAY_N ) { 
    1122                         return $this->last_result[$y] ? array_values(get_object_vars($this->last_result[$y])) : null; 
     1265                        return $this->last_result[$y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null; 
    11231266                } else { 
    11241267                        $this->print_error(/*WP_I18N_DB_GETROW_ERROR*/" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N"/*/WP_I18N_DB_GETROW_ERROR*/); 
    11251268                } 
     
    11341277         * 
    11351278         * @since 0.71 
    11361279         * 
    1137          * @param string|null $query SQL query. If null, use the result from the previous query. 
    1138          * @param int $x Column to return.  Indexed from 0. 
     1280         * @param string|null $query (optional) SQL query. If null, use the result from the previous query. 
     1281         * @param int $x (optional) Column to return.  Indexed from 0. 
    11391282         * @return array Database query result.  Array indexed from 0 by SQL result row number. 
    11401283         */ 
    1141         function get_col($query = null , $x = 0) { 
     1284        function get_col( $query = null , $x = 0 ) { 
    11421285                if ( $query ) 
    1143                         $this->query($query); 
     1286                        $this->query( $query ); 
    11441287 
    11451288                $new_array = array(); 
    11461289                // Extract the column values 
    1147                 for ( $i=0; $i < count($this->last_result); $i++ ) { 
    1148                         $new_array[$i] = $this->get_var(null, $x, $i); 
     1290                for ( $i=0; $i < count( $this->last_result ); $i++ ) { 
     1291                        $new_array[$i] = $this->get_var( null, $x, $i ); 
    11491292                } 
    11501293                return $new_array; 
    11511294        } 
     
    11611304         * @param string $output (optional) ane of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants.  With one of the first three, return an array of rows indexed from 0 by SQL result row number.  Each row is an associative array (column => value, ...), a numerically indexed array (0 => value, ...), or an object. ( ->column = value ), respectively.  With OBJECT_K, return an associative array of row objects keyed by the value of each row's first column's value.  Duplicate keys are discarded. 
    11621305         * @return mixed Database query results 
    11631306         */ 
    1164         function get_results($query = null, $output = OBJECT) { 
     1307        function get_results( $query = null, $output = OBJECT ) { 
    11651308                $this->func_call = "\$db->get_results(\"$query\", $output)"; 
    11661309 
    11671310                if ( $query ) 
    1168                         $this->query($query); 
     1311                        $this->query( $query ); 
    11691312                else 
    11701313                        return null; 
    11711314 
     
    12061349         * 
    12071350         * @since 0.71 
    12081351         * 
    1209          * @param string $info_type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill 
    1210          * @param int $col_offset 0: col name. 1: which table the col's in. 2: col's max length. 3: if the col is numeric. 4: col's type 
     1352         * @param string $info_type(optional) type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill 
     1353         * @param int $col_offset (optional) 0: col name. 1: which table the col's in. 2: col's max length. 3: if the col is numeric. 4: col's type 
    12111354         * @return mixed Column Results 
    12121355         */ 
    1213         function get_col_info($info_type = 'name', $col_offset = -1) { 
     1356        function get_col_info( $info_type = 'name', $col_offset = -1 ) { 
    12141357                if ( $this->col_info ) { 
    12151358                        if ( $col_offset == -1 ) { 
    1216                                 $i = 0; 
     1359                                $i         = 0; 
    12171360                                $new_array = array(); 
    12181361                                foreach( (array) $this->col_info as $col ) { 
    12191362                                        $new_array[$i] = $col->{$info_type}; 
     
    12341377         * @return true 
    12351378         */ 
    12361379        function timer_start() { 
    1237                 $mtime = microtime(); 
    1238                 $mtime = explode(' ', $mtime); 
     1380                $mtime            = explode( ' ', microtime() ); 
    12391381                $this->time_start = $mtime[1] + $mtime[0]; 
    12401382                return true; 
    12411383        } 
     
    12481390         * @return int Total time spent on the query, in milliseconds 
    12491391         */ 
    12501392        function timer_stop() { 
    1251                 $mtime = microtime(); 
    1252                 $mtime = explode(' ', $mtime); 
    1253                 $time_end = $mtime[1] + $mtime[0]; 
     1393                $mtime      = explode( ' ', microtime() ); 
     1394                $time_end   = $mtime[1] + $mtime[0]; 
    12541395                $time_total = $time_end - $this->time_start; 
    12551396                return $time_total; 
    12561397        } 
     
    12661407         * @param string $error_code (optional) A Computer readable string to identify the error. 
    12671408         * @return false|void 
    12681409         */ 
    1269         function bail($message, $error_code = '500') { 
     1410        function bail( $message, $error_code = '500' ) { 
    12701411                if ( !$this->show_errors ) { 
    1271                         if ( class_exists('WP_Error') ) 
     1412                        if ( class_exists( 'WP_Error' ) ) 
    12721413                                $this->error = new WP_Error($error_code, $message); 
    12731414                        else 
    12741415                                $this->error = $message; 
     
    12821423         * 
    12831424         * @since 2.5.0 
    12841425         * @uses $wp_version 
     1426         * @uses $required_mysql_version 
    12851427         * 
    12861428         * @return WP_Error 
    12871429         */ 
     
    12891431                global $wp_version, $required_mysql_version; 
    12901432                // Make sure the server has the required MySQL version 
    12911433                if ( version_compare($this->db_version(), $required_mysql_version, '<') ) 
    1292                         return new WP_Error('database_version',sprintf(__('<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher'), $wp_version, $required_mysql_version)); 
     1434                        return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version )); 
    12931435        } 
    12941436 
    12951437        /** 
     
    13061448        } 
    13071449 
    13081450        /** 
    1309          * Generic function to determine if a database supports a particular feature 
     1451         * has capability 
     1452         * 
     1453         * Determine if a database supports a particular feature 
     1454         * 
     1455         * @since  2.7 
     1456         * @see    db_version() 
     1457         * 
    13101458         * @param string $db_cap the feature 
    13111459         * @param false|string|resource $dbh_or_table (not implemented) Which database to test.  False = the currently selected database, string = the database containing the specified table, resource = the database corresponding to the specified mysql resource. 
    13121460         * @return bool 
     
    13141462        function has_cap( $db_cap ) { 
    13151463                $version = $this->db_version(); 
    13161464 
    1317                 switch ( strtolower( $db_cap ) ) : 
    1318                 case 'collation' :    // @since 2.5.0 
    1319                 case 'group_concat' : // @since 2.7 
    1320                 case 'subqueries' :   // @since 2.7 
    1321                         return version_compare($version, '4.1', '>='); 
    1322                         break; 
    1323                 endswitch; 
     1465                switch ( strtolower( $db_cap ) ) { 
     1466                        case 'collation' :    // @since 2.5.0 
     1467                        case 'group_concat' : // @since 2.7 
     1468                        case 'subqueries' :   // @since 2.7 
     1469                                return version_compare( $version, '4.1', '>=' ); 
     1470                }; 
    13241471 
    13251472                return false; 
    13261473        } 
     
    13361483         * @return string The name of the calling function 
    13371484         */ 
    13381485        function get_caller() { 
    1339                 $bt = debug_backtrace(); 
     1486                $trace  = array_reverse( debug_backtrace() ); 
    13401487                $caller = array(); 
    13411488 
    1342                 $bt = array_reverse( $bt ); 
    1343                 foreach ( (array) $bt as $call ) { 
     1489                foreach ( $trace as $call ) { 
    13441490                        if ( isset( $call['class'] ) && __CLASS__ == $call['class'] ) 
    1345                                 continue; 
     1491                                continue; # filter out function calls of this object's class 
     1492 
    13461493                        $function = $call['function']; 
     1494 
    13471495                        if ( isset( $call['class'] ) ) 
    13481496                                $function = $call['class'] . "->$function"; 
     1497 
    13491498                        $caller[] = $function; 
    13501499                } 
    1351                 $caller = join( ', ', $caller ); 
    13521500 
    1353                 return $caller; 
     1501                return join( ', ', $caller ); 
    13541502        } 
    13551503 
    13561504        /** 
    1357          * The database version number 
    1358          * @param false|string|resource $dbh_or_table (not implemented) Which database to test.  False = the currently selected database, string = the database containing the specified table, resource = the database corresponding to the specified mysql resource. 
     1505         * get database version number 
     1506         * 
     1507         * ADDITIONAL PARAMETER NOTICE 
     1508         * 
     1509         * there once was a proposed second parameter which has never been  
     1510         * implemented. It was describben as "Which database to test" ($dbh_or_table) 
     1511         * 
     1512         * It would have had three different types: 
     1513         * 
     1514         *      false    : currently selected database 
     1515         *  string   : database containing this table 
     1516         *  resource : database by mysql resource 
     1517         * 
     1518         * regarding that third parameter please see {@see db_version()} as well  
     1519         *  
     1520         * @since  2.7 
     1521         * @see    has_cap() 
     1522         * 
    13591523         * @return false|string false on failure, version number on success 
    13601524         */ 
    13611525        function db_version() { 
    1362                 return preg_replace('/[^0-9.].*/', '', mysql_get_server_info( $this->dbh )); 
     1526                return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 
    13631527        } 
    13641528} 
    13651529 
     
    13711535         */ 
    13721536        $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); 
    13731537} 
    1374 ?> 
     1538?> 
     1539 No newline at end of file