01-16-2009, 05:18 AM
|
#29 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Hows this:
PHP Code:
class TalkPHP_Config {
public static $configinfo = array(); protected $dbobj;
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();
}
/** * Create Options * * @return boolean */ public function create($optionname, $optionvalue) { if ( isset($optionname) && isset($optionvalue) ) { $optionname = $this->dbobj->secure($optionname); $optionvalue = $this->dbobj->secure($optionvalue);
$this->dbobj->exeQuery("INSERT INTO `options` VALUES('','$optionname','$optionvalue');");
return true;
}
return false;
}
/** * Remove Options * * @return boolean */ public function remove($optionid) {
if ( is_numeric($optionid) ) { $this->dbobj->exeQuery("DELETE FROM `options` WHERE option_id = $optionid"); return true; }
return false; }
/** * Edit Options * * @return boolean */ public function edit($name, $newname, $newvalue) { if ( isset($name) && isset($newname) && isset($newvalue) ) { $id = $this->name_to_id($name); $newname = $this->dbobj->secure($newname); $newvalue = $this->dbobj->secure($newvalue); $this->dbobj->exeQuery("UPDATE `options` SET `option_name` = '$newname', `option_value` = '$newvalue' WHERE option_id = $id");
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 name_to_id($name) {
if ( isset($name) ) { $name = $this->dbobj->secure($name);
$name_to_id = $this->dbobj->exeQuery("SELECT option_id, option_name FROM `options` WHERE option_name = '$name'");
if ( $name_to_id->rows() > 0 ) { $name_to_id->getFetch(false, true);
return $name_to_id["option_id"]; }
}
return false; }
}
__________________
VillageIdiot can have my babbies ;d
|
|
|
|