EDIT: Nevermind... literally as soon as i posted this, i figured it out... I feel like an idiot now. The solution is I needed to add a parent::connect(DB_HOST, DB_USER, DB_PASS) and $this->select_db to the code apparently
Alrighty, i've been working on this code all day and i've hit a snag. and i might just be that i cannot do exactly it is what i want to do (I googled the hell out of the subject but mostly came up with non related articles, and one article that said i could do what i want...)
but anyway, I've got two classes; siteSettings and siteHeader. siteSettings extends Mysqli and siteHeader extends siteSettings. when i try to connect through the database defined in siteSettings within the siteHeader's coding. I get an error that say mysqli::query cannot fetch siteHeader on line 28.
PHP Code:
<?php class siteHeader extends siteSetting
{
public $html;
public $pid;
function __construct() {
parent::connect(DB_HOST, DB_USER, DB_PASS); parent::select_db('thc_settings');
parent::__construct();
$this->pid = $_GET['pid'];
$this->html .= "<body>";
$this->html .="<div id='site_header'>";
$this->constructHeader();
$this->constructMenu();
$this->html .="</div>";
$this->html .= "</body>";
echo $this->html;
}
function constructHeader()
{
$this->html .= '<h1>'.SITE_NAME.'</h1>';
}
function constructMenu()
{
$que = parent::query('SELECT * FROM pages'); $row = $que->fetch_array();
echo $row[0]; } }
PHP Code:
<?php
class siteSetting extends mysqli
{
private $header;
private $meta;
function __construct() {
$meta = '';
$header = '';
parent::connect(DB_HOST, DB_USER, DB_PASS);
//* Check if The Site is Online, DIE if offline
$this->siteStatus();
//* Get the Meta Information for the site, continue load
$this->getSiteMeta();
$this->getTheme();
echo $this->header;
$this->close(); }
function siteStatus() {
$this->select_db("THC_SETTINGS");
$sql = "SELECT siteStatus FROM settings LIMIT 1;";
$que = $this->query($sql);
if(!$que)
{
die(mysqli_error($this));
}
else
{
while($row = $que->fetch_array())
{
if($row[0] == 'on')
{
NULL;
}
else {
die;
}
}
}
}
function getSiteName() {
parent::connect(DB_HOST, DB_USER, DB_PASS);
$this->select_db('THC_SETTINGS');
$sql = "SELECT siteTitle FROM settings LIMIT 1;";
$que = $this->query($sql);
if(!$que)
{
die(mysqli_error($this));
}
else {
$row = $que->fetch_array();
define("SITE_NAME", $row[0]);
}
}
function getSiteMeta() {
$this->select_db('THC_SETTINGS');
$sql = "SELECT siteMeta, siteDescription FROM settings LIMIT 1;";
$que = $this->query($sql);
if(!$que) {
die(mysqli_error($this));
}
else {
while($row = $que->fetch_array()) {
$this->getSiteName();
$keywords = $row[0];
$desc = $row[1];
$this->meta .= '<html>';
$this->meta .= '<head>';
$this->meta .= '<title>'.SITE_NAME.'</title>';
$this->meta .= '<meta http-equiv="description" content="'.$desc.'">';
$this->meta .= '<meta http-equiv="keywords" content="'.$keywords.'">'; }
return $this->header .= $this->meta;
}
}
function getTheme() {
$this->select_db('THC_SETTINGS');
$que = $this->query('SELECT siteTheme FROM settings'); if(!$que) { define('SITE_THEME', 'default'); } else { $row = $que->fetch_array(); define('SITE_THEME', $row[0]); } return $this->header .= "<link rel='stylesheet' href='./style/".$row[0]."/style.css'>"; } } ?>
also; i appoligize for the sloppiness of my code... its been a good two years since i've worked with PHP and my brains still readjusting to the MATRIX.