Variable storage question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gungneer
Forum Newbie
Posts: 5
Joined: Thu Sep 23, 2010 11:34 am

Variable storage question.

Post by Gungneer »

Ok, I have the plans for a set of scripts all set in my head, except one detail...
I plan on using a possibly large amount of varibles for controling everything from layout to page titles, etc..
Main question I've been wondering is, would it be better to stick all those variables into the database (MySQL, or SQLite most likely) and write a class to call them?
Or would I be best just sticking them in variable files and including them into every page?

From what I can tell, the latter option might rape my server in terms of memory usage, but I don't know for sure.

Main reason I'm asking here is because I've been busy at work recently so I've not had the time to do any tests.

So if anyone knows about the pros and cons for each method I would be greatful for any help with this, and if anyone has even done any benchmark testing or some pish and is willing to share the results, that would be fantastic.

Thanks in advance,
Alan
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Variable storage question.

Post by Jonah Bron »

You could put them into a file and include it. Are these variable containing HTML? Actually, you should put all values into an associative array. It makes things so much neater.

Another option is to use parse_ini_file().

http://php.net/parse-ini-file
Gungneer
Forum Newbie
Posts: 5
Joined: Thu Sep 23, 2010 11:34 am

Re: Variable storage question.

Post by Gungneer »

Jonah Bron wrote:You could put them into a file and include it. Are these variable containing HTML? Actually, you should put all values into an associative array. It makes things so much neater.

Another option is to use parse_ini_file().

http://php.net/parse-ini-file
Umm.. That's what I already do...
No, they don't contain any HTML.
And I ALWAYS use associative arrays.

What I'm asking here is if doing this would be better than storing them all in the data base and calling them when I need the specific vars because as it stands, I feel I have a lot of vars in my files already, and should I go with the method that's in my head for making a site, I would be looking at possibly storing a fair bit of data in vars mostly related to page information and layout.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Variable storage question.

Post by Jonah Bron »

Gungneer wrote:Umm.. That's what I already do...
I know. I'm just saying that's fine.
Gungneer wrote:No, they don't contain any HTML.
Good.
Gungneer wrote:What I'm asking here is if doing this would be better than storing them all in the data base
I read what you've said about the data so far, but what exactly are they holding? Can you give an example? And how many variables have you defined?
Post Reply