Well, your parse error is this line:
optionally enclosed by '"'
...which needs to have that double-quote escaped, like...
optionally enclosed by '\"'
It will happen again a few lines later.
After that, I doubt you'll be happy yet, as calling the $sql variable by itself won't actually do anything in the database.