I may be trying to do the wrong thing here, but I am wanting to setup a persistent mySQL connection to a specific data table from inside an object instance. The mySQL connection uses a data manager class (MysqlD😎 to wrap the Mysql access.
The BasicPage class creates a connection and sets a query in the constructor, as below. However if I try to access the connection via $this->$db->any_function() from any other function within the class, the $db no longer points to the database.
How can I make the instantiation in the constructor persistent?
class BasicPage {
// Class variables
var $PageName;
var $PageArray;
var $PageNumItems;
var $PageCurrIndex;
var $db;
////////////////////////////////////////////////////////////////////////
// constructor
////////////////////////////////////////////////////////////////////////
/**
Constructor
*/
function BasicPage($name=''){
$this->$_PageName = $name;
$this->$db = new MysqlDB('', 'mysql', RES_ASSOC);
if ($this->$db->connect(DB_SERVER, DB_NAME, DB_USER, DB_PASSWORD, true)) {
if ($this->$db->query("SELECT sequence,section_name,html FROM site_page where page_name='${name}' order by sequence")) {
$numItems = $this->$db->numRows();
if ($numItems > 0) {
$this->$PageArray = $this->$db->getNext();
$this->$PageCurrIndex = 0;
}
}
else{
echo "BasicPage:Query failed";
}
}
}
}//End Class