Drupal database connection
The database connection is handled elsewhere, you do not need to write a new connection function in your template file.  

You can use this:
https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_query/7