title: How can I have access to the Drupal 7 $database variable?
body: <p>I have written some php/mysql queries inside node.tpl.php and page.tpl.php.</p>
  
  <p>The username and password that these pages use to connect to MySQL are specified within the files.</p>
  
  <p>Instead of doing this, I would like to be able to use the MySQL connection settings that are defined in Drupal's settings.php file.</p>
  
  <p>I am trying, unsuccessfully include the settings.php file into node.tpl.php and page.tpl.php.</p>
  
  <pre><code>&lt;?php include("sites/default/settings.php") ?&gt; 
  </code></pre>
  
  <p>Then I am trying to access the $databases array from settings.php like this:</p>
  
  <pre><code>$databases['default']['default']['username']
  </code></pre>
  
  <p>The $databases array has this structure:</p>
  
  <pre><code>$databases = array (
                     'default' =&gt; 
                          array (
                            'default' =&gt; 
                                 array (
                                      'database' =&gt; 'sdnndr',
                                      'username' =&gt; 'root',
                                      'password' =&gt; '',
                                      'host' =&gt; 'localhost',
                                      'port' =&gt; '',
                                      'driver' =&gt; 'mysql',
                                      'prefix' =&gt; '',
                                  ),
                          ),
                );
  </code></pre>
  
  <p>My approach is not working. Can anyone suggest</p>