Secondo te cosa dovresti stampare per verificare che $sql contenga effettivamente la query che vuoi eseguire?