Make WordPress Core

Ticket #26847: 26847.4.diff

File 26847.4.diff, 1.8 KB (added by pento, 11 years ago)
  • src/wp-includes/wp-db.php

     
    510510        public $is_mysql = null;
    511511
    512512        /**
     513         *  A list of MySQL's SQL modes to disable when connecting.
     514         *
     515         * @since 3.9.0
     516         * @see wpdb::set_sql_mode()
     517         * @access protected
     518         * @var array
     519         */
     520        protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY',
     521                'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' );
     522
     523        /**
    513524         * Connects to the database server and selects a database
    514525         *
    515526         * PHP5 style constructor for compatibility with PHP5. Does
     
    649660        }
    650661
    651662        /**
     663         * Ensures the connection's sql_mode is WordPress-compatible
     664         *
     665         * @since 3.9.0
     666         *
     667         * @param resource $dbh The resource given by mysql_connect
     668         */
     669        function set_sql_mode( $dbh ) {
     670                $res = mysql_query( 'SELECT @@SESSION.sql_mode;', $dbh );
     671                if ( ! $res ) {
     672                        return;
     673                }
     674
     675                $modes_str = mysql_result( $res, 0 );
     676
     677                if ( empty( $modes_str ) ) {
     678                        return;
     679                }
     680
     681                $modes = explode( ',', $modes_str );
     682                $modes = array_change_key_case( $modes, CASE_UPPER );
     683
     684                $incompatible_modes = (array)apply_filters( 'incompatible_sql_modes', $this->incompatible_modes );
     685
     686                if ( empty( $incompatible_modes ) ) {
     687                        return;
     688                }
     689
     690                foreach( $modes as $i => $mode ) {
     691                        if ( in_array( $mode, $incompatible_modes ) ) {
     692                                unset( $modes[ $i ] );
     693                        }
     694                }
     695
     696                $modes_str = implode( ',', $modes );
     697
     698                mysql_query( "SET SESSION sql_mode='$modes_str';", $dbh );
     699        }
     700
     701        /**
    652702         * Sets the table prefix for the WordPress tables.
    653703         *
    654704         * @since 2.5.0
     
    11701220
    11711221                $this->set_charset( $this->dbh );
    11721222
     1223                $this->set_sql_mode( $this->dbh );
     1224
    11731225                $this->ready = true;
    11741226
    11751227                $this->select( $this->dbname, $this->dbh );