title: OOP database connect/disconnect class
body: <p>I have just started learning the concept of Object oriented programming and have put together a class for connecting to a database, selecting database and closing the database connection. So far everything seems to work out okay except closing the connection to the database. </p>
  
  <pre><code>    class Database {
  
      private $host, $username, $password;
      public function __construct($ihost, $iusername, $ipassword){
          $this-&gt;host = $ihost;
          $this-&gt;username = $iusername;
          $this-&gt;password = $ipassword;
      }
      public function connectdb(){
          mysql_connect($this-&gt;host, $this-&gt;username, $this-&gt;password)
              OR die("There was a problem connecting to the database.");
          echo 'successfully connected to database&lt;br /&gt;';
      }
      public function select($database){
          mysql_select_db($database)
              OR die("There was a problem selecting the database.");
          echo 'successfully selected database&lt;br /&gt;';
      }
      public function disconnectdb(){
          mysql_close($this-&gt;connectdb())
              OR die("There was a problem disconnecting from the database.");
      }
  }
  
  $database = new database('localhost', 'root', 'usbw');
  $database-&gt;connectdb();
  $database-&gt;select('msm');
  $database-&gt;disconnectdb();
  </code></pre>
  
  <p>When I attempt to disconnect from the database I get the following error message:</p>
  
  <pre><code>Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in F:\Programs\webserver\root\oop\oop.php on line 53
  </code></pre>
  
  <p>I'm guessing it isn't as simple as placing the connectdb method within the parenthesis of the mysql_close function but can't find the right way to do it.</p>
  
  <p>Thanks</p>