12-30-2008, 10:55 PM
|
#1 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
The Config Class
UPDATE
Heres what I have so far in this config class:
LATEST
PHP Code:
class TalkPHP_Config {
// -- Public members -- // public static $configinfo = array();
// -- Private members -- // private $iSettingID;
private $sSettingname;
private $sSettingvalue;
// -- Protected members -- //
protected $dbobj;
// -- Deprecated // protected $query;
public function __construct($dbObj) {
if ( is_object($dbObj) && $dbObj instanceof DBMysql ) { $this->dbobj = $dbObj; } else throw new Exception( "Database Object failed, error called." );
self::grabOptions();
}
public function &option($optionname, $optionvalue) {
if ( isset($optionname) && isset($optionvalue) ) {
$this->sSettingname = $optionname; $this->sSettingvalue = $optionvalue;
} return false;
}
/** * Create Options * * @return boolean */ public function create($optionname, $optionvalue) { $this->sSettingname = $optionname; $this->sSettingvalue = $optionvalue; if ( isset($this->sSettingname) && isset($this->sSettingvalue) ) { $this->sSettingname = $this->dbobj->secure($this->sSettingname); $this->sSettingvalue = $this->dbobj->secure($this->sSettingvalue);
$this->dbobj->exeQuery("INSERT INTO `options` VALUES('','$this->sSettingname','$this->sSettingvalue');");
return true;
}
return false;
}
/** * Remove Options * * @return boolean */ public function remove($optionid) { $this->iSettingID = $optionid;
if ( is_numeric($this->iSettingID) ) { $this->dbobj->exeQuery("DELETE FROM `options` WHERE option_id = $this->iSettingID"); return true; }
return false; }
/** * Edit Options * * @return boolean */ public function edit() { if ( isset($this->sSettingname) && isset($this->sSettingvalue) ) { $this->sSettingname = $this->dbobj->secure($this->sSettingname); $this->sSettingvalue = $this->dbobj->secure($this->sSettingvalue); $name2id = self::Name2Id(); $this->dbobj->exeQuery("UPDATE `options` SET `option_name` = '$this->sSettingname', `option_value` = '$this->sSettingvalue' WHERE option_id = $name2id");
return true;
} return false; }
/** * Grab all the Options * */ private function grabOptions() { $options = $this->dbobj->exeQuery("SELECT option_id, option_name, option_value FROM `$this->table`");
if ( $options->rows() > 0 ) {
while ( $options->getFetch(false, true) ) { $this->configinfo["$options[option_name]"] = $options[option_value]; }
return true;
} return false;
}
/** * Converts the Name to the Id of the settings * * @return int */ private function Name2Id() {
if ( isset($this->sSettingname) ) { $this->sSettingname = $this->dbobj->secure($this->sSettingname);
$name2id = $this->dbobj->exeQuery("SELECT option_id, option_name FROM `$this->table` WHERE option_name = '$this->sSettingname'");
if ( $name2id->rows() > 0 ) { $name2id->getFetch(false, true);
return $name2id["option_id"]; }
} //else trigger_error( self::ERR_SETTINGS_NAME_EMPTY, E_USER_ERROR );
return false; }
}
__________________
VillageIdiot can have my babbies ;d
Last edited by Orc : 01-16-2009 at 05:03 AM.
|
|
|
|