Database connection in constructor and destructor I am playing with different ways to do database interaction in PHP, and one of the ideas I have been playing with is connecting to the DB in the constructor and disconnecting in the destructor. This is the code from my Database class.

function __construct()
{
  $this-&gt;link = mysql_connect($this-&gt;server.':'.$this-&gt;port, $this-&gt;username);
  if(!$this-&gt;link)
    die('Could not connect: '.mysql_error());

  if(!mysql_select_db($this-&gt;database, $this-&gt;link))
    die('Could not select database: '.mysql_error());
}    

function __destruct()
{
  if(mysql_close($this-&gt;link))
    $this-&gt;link = null; 
}


This works well, my only reservation is that if I need to connect several to hit the database several times it will do multiple connections and disconnects. If I do that a lot I can see, maybe, potential problems. Is this a concern or is there a better way to do this? And is my code even up to snuff in general?
You could use MySQLi (PHP extension) which is class based by default instead of MySQL. It 
is very easy to set up multiple connections. You are, however, required to know the connection you are querying always.



Congrats with the first question.