Make WordPress Core

Ticket #26847: 26847.2.diff

File 26847.2.diff, 1.7 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                foreach( $modes as $i => $mode ) {
     685                        if ( in_array( $mode, $this->incompatible_modes ) ) {
     686                                unset( $modes[ $i ] );
     687                        }
     688                }
     689
     690                $modes_str = implode( ',', $modes );
     691
     692                mysql_query( "SET SESSION sql_mode='$modes_str';", $dbh );
     693        }
     694
     695        /**
    652696         * Sets the table prefix for the WordPress tables.
    653697         *
    654698         * @since 2.5.0
     
    11701214
    11711215                $this->set_charset( $this->dbh );
    11721216
     1217                $this->set_sql_mode( $this->dbh );
     1218
    11731219                $this->ready = true;
    11741220
    11751221                $this->select( $this->dbname, $this->dbh );