I would test this by just simply connecting to the database first without sending a SQL query. If this works without a problem, you know where your issue lies..