DeGauss wrote:Just don't fall into the trap of trying to use classes with everything from now on.

Rgr. All you really need is:
Code: Select all
<?php
$connect = mysql_connect( $host , $user , $pass );
$sql = mysql_select_db( $dbname , $connect );
if(!$connect) {
echo mysql_error();
?>
You don't need the overhead of a class - or even a function definition.
Of course, you maybe plan to add in other functionality to the class, or maybe you just wanted a simple example to start off writing classes.
I think, as a general rule, classes are a good way to go if you have lots of functions in a script which share several variables and it's hard to pass them all sequentially but, for efficient code, don't use classes if you can do it with functions and don't use functions if you can just write some loose code.