in reply to ODBC

I would recommend:
And after you do $sql=... do a print "SQL=$sql" bit so you can visually see what exactly is being processed.