Drupal 7 returning empty array because of the database connection
I resolved it. The problem is not in the database connection. I cleared the cache table in the database and it started working fine. 

Earlier, I set the option 'Cache pages for anonymous users'. May be because of this, it didn't give the output. 

Thanks for your answer.