changed $query to sql