If you don't want to turn WP_DEBUG/WP_DEBUG_DISPLAY off, the following fix worked for me:-
Replace the line:-
$dm_domain = $wpdb->escape( $_SERVER[ 'HTTP_HOST' ] );
with:-
$dm_domain = addslashes( $_SERVER[ 'HTTP_HOST' ] );
As far as I can tell, addslashes is all that the $wpdb->escape method was doing in this case, so it should be equivalent.