I still have not been able to figure this out. How can we access a one class object in another class?
I am using the below code but I am getting and error:
class ListofRecord{
var $db;
function __construct(){
$db = global $db;
}
function record(){
$record = $this->db->SelectQuery("SELECT * FROM user order by UID ASC");
return $record;
}
}
You need to refer to the global
$dbvariable first and then use it in a statement. You also have a minor syntax error in your constructor. You forgot to use the$thiskeyword when referring your your$dbproperty.It also is a better practice not to use global variables and instead pass any variables that you need as parameters to your method call. In this case it is your constructor: