Index: src/wp-includes/wp-db.php
===================================================================
--- src/wp-includes/wp-db.php	(revision 26958)
+++ src/wp-includes/wp-db.php	(working copy)
@@ -649,6 +649,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 ) {
+		$incompatible_modes = array(
+			'STRICT_TRANS_TABLES',
+			'STRICT_ALL_TABLES',
+			'NO_ZERO_DATE',
+			'TRADITIONAL'
+		);
+
+		$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 );
+
+		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 +1209,8 @@
 
 		$this->set_charset( $this->dbh );
 
+		$this->set_sql_mode( $this->dbh );
+
 		$this->ready = true;
 
 		$this->select( $this->dbname, $this->dbh );
