If I run exactly the same syntax just from the command line, it does work, but as soon as I put it in $cmd from the script, it doesn't.
Btw, I have tried to use DBI, but in order to set the connection there are quite a few steps which I cannot do due to some reasons :(