[nycphp-talk] Storing User Controlled Configs
Jeff Rigby
jrigby at mac.com
Tue Sep 7 00:25:47 EDT 2004
Hello, my name is Jeff Rigby, this is my first time posting and I'm
very interested in getting involved with this list.
I wanted to get some advice on the best and most efficient way to store
user controlled configurations. I am currently storing all non-security
risk configurations in a MySQL table named 'config'. When the user logs
in I run a query to get all the configs from the table and then I store
them in a session variable with the following function:
// Set $force to 1 if configurations needs to be reloaded.
function getConfig($force) {
if($force==1 || $_SESSION['config_set']!=1) {
$db = connectDB();
$query = 'SELECT * FROM config';
$results = $db->query($query);
while($row = $results->fetchRow(DB_FETCHMODE_ASSOC)) {
$_SESSION['config_'.$row['config_name']] =
$row['config_value'];
}
$_SESSION['config_set'] = 1;
$db->disconnect();
}
}
This way, unless I update a configuration, I only need to to query the
SQL table once per a session. It seems to work fine.
My questions are:
1. Would it be better to query the table on every page load?
2. What are the drawbacks if any of using session vars to store configs?
3. Is there a better method?
4. Is it proper to call session vars from within a function, or should
the the session vars be passed to the variable when the function is
called?
Example
function test() {
RETURN 'Hello '.$_SESSION['config_name'].'!';
}
test();
or
function test($name) {
RETURN 'Hello '.$name.'!';
}
test($_SESSION['config_name']);
Thanks in advance for all your help.
Jeff
More information about the talk
mailing list