PDA

View Full Version : configure variables


xiaodao
12-07-2004, 02:25 AM
well i hope you can understand what i mean?
for example, the back end of this forum got some general configuration where sitename, titles and other variables are able to be modified, i wonder that do they keep these variables in database? or what other method they do? also if they keep in database, is it efficient to enquire the variable from database every time?

Fou-Lu
12-07-2004, 02:42 AM
A database is best for such a configuration, you only want to hard code what you don't want to be able to change easily. However, you do not need to run a query every time, if you use datastore techniques or add such information to a global array.
There are many ways of doing such things, but I find that a combined query an adding it to a global function makes good use of defining the information that I need, and eliminating the queries that I don't need.
Just remember though, that mySQL is not your enemy, keep your queries under... say about 20 a page (which is still a lot) and your good to go.

xiaodao
12-07-2004, 04:00 AM
but I find that a combined query an adding it to a global function makes good use of defining the information that I need,
can give an example

Fou-Lu
12-07-2004, 10:38 AM
Lets see, if you have something like settings, containing information such as the names, urls, copyrights, styles, ipbans, timeformats, etc, and another table with information relative to this, you can combine these tables with an inner or left join query, or use two individual queries. Frankly, I find that two individuals have a slightly increased performance, but it adds the whole additional query. Then you allow a globals passthrough to let the resulting array access from any script, and your good as gold. To stop it from querying again, you simply add something like:

if (isset($OPTIONS))
{
return $OPTIONS;
}
else
{
// This is where you would do a query for it.
}

I find that this method will usually eliminate the need to gather your variables everytime your script executes. Just make sure you use such a thing only when you need to gather information that you don't expect to change, such as your configurations. If they do change, the created cache should stop you from being able to view these changes for the moment, which is also a good way to test it out.

xiaodao
12-07-2004, 12:00 PM
Fou-Lu, you have a site? offer one of this tutorial?

Fou-Lu
12-07-2004, 02:24 PM
No I'm sorry I don't. Think of it kind of like a cache, you could also create a datastore if you needed it.
Anything in specific your looking for?