I am using a config table with a name (config_name) and a value (config_value). I even add a help field so that users can see what the name / value pair is for, or where it is used.
CREATE TABLE config ( config_id bigint unsigned NOT NULL auto_increment, config_name varchar(128) NOT NULL, config_value text NOT NULL, config_help text COMMENT 'help', PRIMARY KEY (config_id), UNIQUE KEY ix_config_name (config_name), ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Then the following php code returns a value for the key or returns an empty string. $ Db is supposed to be an open database connection. All entries are forced to enter lowercase letters.
function getConfigValue($name) { $retval=''; $db = $this->db; $sql = 'select config_value from config where LOWER(config_name)="'.strtolower($name).'"'; $result = $db->Query($sql); if ($result) { $row = $db->FetchAssoc($result); $retval = $row['config_value']; } return $retval; }
In this case, all mysql / php, but the general principle remains.
rainecc
source share