It really annoys me when I see scripts people have made with the site configuration written in to the database. I know it shouldn't but I just see it as a waste of database resources and an unnecessary load on the database as well.
My site config always gets written in to a config.php file, usually in a lib/ directory. Also, making a nice little interface in the sites admin panel to easily configure and change the config is a bonus as well.
Creating an efficient site always requires knowing what actually needs inserting in to a database and what can be stored in a local flat file. Creating a database table to store values which will remain constant for all users is not recommended. An example of this would be standard site config such as the title of the website, or copyright owner of the website (More dynamic to put these values in to a variable which can be called on multiple pages than hard-coding it in pages then having to manually change them all later). There is no reason you can't just put this information in to a config file, and your database will not have to run through a query, select the information then extract it and organise it on every single page every single user loads. Instead you call two variables from a file, that's it.
To avoid database load on sites which have the potential to have hundreds or thousands of registered users I always try to avoid putting data in to the database that doesn't need to be there. Say you have your own PHP RPG game, there is a module system in place for admins to install and uninstall modules (additional content) from the game. Instead of creating a database table with the information needed for these modules, I create a module list file with the file permission 0666 (read/write). Here is an example:
$getaddon[] = "[link=boss][name=The Boss][priv=SuperAdminModUser]";
$getaddon[] = "[link=airport][name=Airport][priv=SuperAdminModUser]";
$getaddon[] = "[link=gym][name=Gym][priv=SuperAdminModUser]";
So now we have a php file called list.php with an array inside of different strings that we can loop through using a foreach() statement. This is similar to BBCode because it is an easy format to process using the preg_replace() function.
foreach($getaddon as $row){
$link = preg_replace('/\[link=(.*?)\]\[name=/is');
$name = preg_replace('/\[name=(.*?)\]\[priv=/is');
$priv = preg_replace('/\[priv=(.*?)\]/is');
}
So now we have the link, name and user privelages inside a variable, but we need to do something with those variables before they get overwritten by the next loop of the foreach statement, so how about echoing an url to load the module.
foreach($getaddon as $row){
$link = preg_replace('/\[link=(.*?)\]\[name=/is');
$name = preg_replace('/\[name=(.*?)\]\[priv=/is');
$priv = preg_replace('/\[priv=(.*?)\]/is');
if (strpos($priv, $_SESSION['user']['type']) === true){
echo '<a href="http://www.mysite.com/modules/'.$link.'.php">'.$name.'</a><br />';
}
}
So assuming you had a variable named $_SESSION['user']['type'] and it contains the string 'User', each link will be echoed on the page and look like this
The Boss
Airport
Gym
Now this method of calling data from a flat file is a lot more efficient than creating a database table like this,
CREATE TABLE `modules` (
`id` int(5) NOT NULL,
`name` varchar(20) NOT NULL,
`link` varchar(20) NOT NULL,
`priv` enum('Super', 'Admin', 'Mod', 'User') NOT NULL,
`installed` enum('Yes', 'No') NOT NULL,
PRIMARY KEY (`id`)
);
So although it may be easier for you to call this information from the database using a mysql_query() statement and updating the information as well, in the long run it will start to drag down your database speed unnecessarily.
So that's a short description of why I prefer using config files instead of a database to store my sites config information lol