Index: src/wp-includes/wp-db.php
===================================================================
--- src/wp-includes/wp-db.php	(revision 28187)
+++ src/wp-includes/wp-db.php	(working copy)
@@ -1548,7 +1548,7 @@
 			$this->last_error = mysql_error( $this->dbh );
 		}
 
-		if ( $this->last_error ) {
+		if ( $this->last_error || ! is_object( $this->result ) ) {
 			// Clear insert_id on a subsequent failed insert.
 			if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) )
 				$this->insert_id = 0;
