Make WordPress Core

Ticket #26847: 26847.diff

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

     
    649649        }
    650650
    651651        /**
     652         * Ensures the connection's sql_mode is WordPress-compatible
     653         *
     654         * @since 3.9.0
     655         *
     656         * @param resource $dbh The resource given by mysql_connect
     657         */
     658        function set_sql_mode( $dbh ) {
     659                $incompatible_modes = array(
     660                        'STRICT_TRANS_TABLES',
     661                        'STRICT_ALL_TABLES',
     662                        'NO_ZERO_DATE',
     663                        'TRADITIONAL'
     664                );
     665
     666                $res = mysql_query( 'SELECT @@SESSION.sql_mode;', $dbh );
     667                if ( ! $res ) {
     668                        return;
     669                }
     670
     671                $modes_str = mysql_result( $res, 0 );
     672
     673                if ( empty( $modes_str ) ) {
     674                        return;
     675                }
     676
     677                $modes = explode( ',', $modes_str );
     678
     679                foreach( $modes as $i => $mode ) {
     680                        if ( in_array( $mode, $incompatible_modes ) ) {
     681                                unset( $modes[ $i ] );
     682                        }
     683                }
     684
     685                $modes_str = implode( ',', $modes );
     686
     687                mysql_query( "SET SESSION sql_mode='$modes_str';", $dbh );
     688        }
     689
     690        /**
    652691         * Sets the table prefix for the WordPress tables.
    653692         *
    654693         * @since 2.5.0
     
    11701209
    11711210                $this->set_charset( $this->dbh );
    11721211
     1212                $this->set_sql_mode( $this->dbh );
     1213
    11731214                $this->ready = true;
    11741215
    11751216                $this->select( $this->dbname, $this->dbh );