I'm having some issues with a script that doesn't seem to be doing what I want it to do.
I would greatly appreciate some fresh eyes over the following code.
From what I gather the __construct() for the Settings class isn't getting used?
Am I right in thinking it should take precedence over the 'parent' Core class __construct()?
class Core
{
public $dbname;
public $tablename;
public $fieldlist;
public $arrData;
function __construct() {
$this->dbname = 'default';
$this->tablename = 'default';
$this->fieldlist = array('column1', 'column2', 'column3');
$this->fieldlist['column1'] = array('pkey' => 'y');
} // constructor
function getData ($where)
{
echo $this->name;
$this->arrData = array();
$this->numrows = 0;
global $dbconnect, $query;
$dbconnect = db_connect($this->dbname);
if (empty($where)) {
$where_str = NULL;
}
else {
$where_str = "WHERE $where";
} // if
$query = "SELECT * FROM $this->tablename $where_str";
echo $query;
// The above query echo's
// SELECT * FROM default
// where it *should* echo SELECT * FROM settings
// it seems the Core __construct() is overwriting the subclass __construct()
// ????
$result = mysql_query($query, $dbconnect);
while ($row = mysql_fetch_assoc($result)) {
$this->arrData[] = $row;
} // while
mysql_free_result($result);
return $this->arrData;
} // end getData
} // end core class
class Settings extends Core
{
function __contruct()
{
$this->tablename = 'settings';
$this->fieldlist = array('id', 'settings_name', 'settings_value');
$this->fieldlist['id'] = array('pkey' => 'y');
$this->fieldlist['settings_name'] = array('pkey' => 'n');
$this->fieldlist['settings_value'] = array('pkey' => 'n');
} // end class constructor
} // end Settings class
and the creation:
include 'includes/core.class.php';
$dbobject = new Settings;
$where = "";
$settings = $dbobject->getData($where);
I'm new to OOP so all help/thoughts welcome.
Cheers,
Nawrik.