title: Close a MySQL connection using PHP OOP
body: <p>I'm trying to learn PHP OOP and have come upon a problem. I'm trying to open and close connection using OOP like this</p>
  
  <pre><code>class db{
      public  function opendb(){
          $server = mysql_connect("localhost","root","") or die ("Couldn't connect to server");
          $db = mysql_select_db("test",$server) or die ("Couldn't connect to database");
          mysql_query("set character_set_server='utf8'");
          mysql_query("set names 'utf8'");    
      }
  
  public function closedb(){
          mysql_close($server);   
      }   
  }
  </code></pre>
  
  <p>and use this code in my PHP page</p>
  
  <pre><code>$x = new db;
  $x-&gt;closedb();
  </code></pre>
  
  <p>and make queries like this</p>
  
  <pre><code>$x = new db;
  $x-&gt;opendb();
  </code></pre>
  
  <p>but I get an error because the <code>$server</code> is not accessible from inside the second function. How can I do that?</p>