Index: src/wp-includes/wp-db.php
===================================================================
--- src/wp-includes/wp-db.php	(revision 27045)
+++ src/wp-includes/wp-db.php	(working copy)
@@ -510,6 +510,17 @@
 	public $is_mysql = null;
 
 	/**
+	 *  A list of MySQL's SQL modes to disable when connecting.
+	 *
+	 * @since 3.9.0
+	 * @see wpdb::set_sql_mode()
+	 * @access protected
+	 * @var array
+	 */
+	protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY',
+		'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' );
+
+	/**
 	 * Connects to the database server and selects a database
 	 *
 	 * PHP5 style constructor for compatibility with PHP5. Does
@@ -649,6 +660,45 @@
 	}
 
 	/**
+	 * Ensures the connection's sql_mode is WordPress-compatible
+	 *
+	 * @since 3.9.0
+	 *
+	 * @param resource $dbh The resource given by mysql_connect
+	 */
+	function set_sql_mode( $dbh ) {
+		$res = mysql_query( 'SELECT @@SESSION.sql_mode;', $dbh );
+		if ( ! $res ) {
+			return;
+		}
+
+		$modes_str = mysql_result( $res, 0 );
+
+		if ( empty( $modes_str ) ) {
+			return;
+		}
+
+		$modes = explode( ',', $modes_str );
+		$modes = array_change_key_case( $modes, CASE_UPPER );
+
+		$incompatible_modes = (array)apply_filters( 'incompatible_sql_modes', $this->incompatible_modes );
+
+		if ( empty( $incompatible_modes ) ) {
+			return;
+		}
+
+		foreach( $modes as $i => $mode ) {
+			if ( in_array( $mode, $incompatible_modes ) ) {
+				unset( $modes[ $i ] );
+			}
+		}
+
+		$modes_str = implode( ',', $modes );
+
+		mysql_query( "SET SESSION sql_mode='$modes_str';", $dbh );
+	}
+
+	/**
 	 * Sets the table prefix for the WordPress tables.
 	 *
 	 * @since 2.5.0
@@ -1170,6 +1220,8 @@
 
 		$this->set_charset( $this->dbh );
 
+		$this->set_sql_mode( $this->dbh );
+
 		$this->ready = true;
 
 		$this->select( $this->dbname, $this->dbh );
