a simple question about connection class

hi, i’m an oop-noob, i have a simple class mysql_connection, like this:

[php]
class mysql_connection {

private $connection;

public function connect() {

$this->connection = mysql_connect( HOST, NAME, PASS );

mysql_select_db( DB, $this->connection );

return $this->connection;

}
}
[/php]

just a simple question, whitch is the better way to use it?

[php]
$connect = new mysql_connection();
$connect->connect();
mysql_query(“SELECT * FROM table”, $connect->connect() );
mysql_query(“SELECT * FROM table2”, $connect->connect() );
[/php]

or?

[php]
$connect = new mysql_connection();
$db = $connect->connect();
mysql_query(“SELECT * FROM table”, $db );
mysql_query(“SELECT * FROM table2”, $db );
[/php]

and for use it in others class i need to extends? like:

[php]
class query extends mysql_connect {

public function run_query( $query ) {

mysql_query( $query, $this->connect() );

}
}
[/php]

or better using globals?

[php]
class query {

public function run_query( $query ) {

mysql_query( $query, $GLOBALS[‘db’] );

}
}
[/php]

or by passing the $con var in each class function?

[php]
class query {

public function run_query( $query, $con ) {

mysql_query( $query, $con );

}
}
[/php]

i really appriciate if someone could help me ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service