I am making a mini CMS for two sites and am storing some basic things like a “Title Name” that will be displayed on every page, “Phone Number” etc
The most direct thing to do, would be perform a query every time a page loads to access the title name and print it to screen. This however seems to be an unnecessary thing.
I am weighing up the following options:
-
When a user saves the site title, a file is printed, ie. ‘site_name.txt’ which simply stores the site’s name; when the site name is needed this file is merely included.
-
A config file is written/updated every time one of these repetatively used variables is changed. These variables could be stored like so:
$site_title = “insert name here”;
$phone_number = “xxx’;
Then simply include this config file on every page and refer to the variables.
Is this how sites like WordPress do things?
Am I wasting my time thinking about this or is it worthwhile thinking of ways to reduce sql calls on a CMS like this that has a lot of custom data stored in a db? Are there other options I’m unaware of that are far more efficient?
Thanks for your time.
It seems fine to keep it in a config file, but if you want more than one site on your system, then you would have to handle that somehow. I also see no problem in keeping that information in the database, but I would suggest implementing a simple cache if you choose to do so. When you need the page title, for instance, you check to see if it is cached. If it is, you take it from there, and if not, you run a database query. That will save you many, many SQL queries over time and thereby eliminates the main reason to not store this data in the database.