title: ADOdb - PHP + MySQL class scope and connection
body: <p>I've just switched over to using ADODB with MySQL and PHP... I'm having troubles with connecting to the database. Before, I could just have one global connection to the database and run queries of of that, but now it seems I need a new connection in each class?</p>
  
  <p>Is that how it's supposed to work or am I doing something wrong?</p>
  
  <p><strong>Connection made in config file:</strong></p>
  
  <pre><code>include 'admin/db/adodb.inc.php';
  $DB = NewADOConnection('mysql');
  $DB-&gt;Connect($server, $db_user, $db_pwd, $db);
  </code></pre>
  
  <p><strong>Class used:</strong></p>
  
  <pre><code>class getuser {
      public function __construct($user_id) {
          $userquery = $DB-&gt;Execute("SELECT * FROM users WHERE id = '".$user_id."'");
          while($user = $userquery-&gt;FetchRow()){
              $this-&gt;uid = $user['id'];
              $this-&gt;username = $user['username'];
              $this-&gt;email = $user['email'];
          }
      }
  }
  </code></pre>
  
  <p>The variables used to connect are all set fine. If I were to include the config file itself within then class the it works fine, so it must be to do with the scope of $DB?</p>
  
  <p>Obviously I don't want to have a new database connection for each class / query...</p>
  
  <p>Also, do I need to worry about closing the connection at any point?</p>
  
  <p>Many thanks in advance</p>
  
  <p>Tim</p>