basically the problem is:
$dm_domain = $wpdb->escape( $_SERVER[ ‘HTTP_HOST’ ] );
the escape can be left out, as afterwards $dm_domain
is in the query in a prepared statement – meaning it’s just a waste to escape it beforehand. And it’s a $_SERVER variable anyway
$dm_domain = $_SERVER[ 'HTTP_HOST' ];
will do the trick