Code: Select all
<?php
//scroll down to: //Here I'm lost...
class DB{
var $link;
var $QueryResult;
function DB($strDB_Host, $strDB_User, $strDB_Password, $strDefaultDB){
$this->link = mysql_connect($strDB_Host , $strDB_User , $strDB_Password);
mysql_select_db($strDefaultDB);
}
function query($strSQL){
$result = mysql_query($strSQL,$this->link);
$this->QueryResult = $result;
return $result;
}
}
$DB = new DB('DB_Host', 'DB_User', 'DB_Password', 'DefaultDB');
class B{
function B(){
//Here I'm lost
$DB->query('update something');
}
}
$B = new B;
?>I think it is by reference in some way, but I don't really get how...
Or should I store the objects in the session like this:?
Code: Select all
<?php
class DB{
var $link;
var $QueryResult;
function DB($strDB_Host, $strDB_User, $strDB_Password, $strDefaultDB){
$this->link = mysql_connect($strDB_Host , $strDB_User , $strDB_Password);
mysql_select_db($strDefaultDB);
}
function query($strSQL){
$result = mysql_query($strSQL,$this->link);
$this->QueryResult = $result;
return $result;
}
}
//Session var instead
$_SESSION['DB'] = new DB('DB_Host', 'DB_User', 'DB_Password', 'DefaultDB');
class B{
function B(){
//Session var instead
$_SESSION['DB']->query('update something');
}
}
//Session var instead
$_SESSION['B'] = new B;
?>