Building a table of constants

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
David McWilliams
Forum Newbie
Posts: 1
Joined: Wed Sep 10, 2003 10:23 am

Building a table of constants

Post by David McWilliams »

All of my pages refer to a 20x100 table of "constant" data, with each page using a few rows or columns. I am looking for the most efficient way to store this table.

I've come up with a couple obvious ways, but they both have drawbacks. I'm hoping someone more experienced could point to a better way.


Method 1: Create an include file, where I build the table using arrays.
+Only one line of code required to get full access to the table.
-Must build the 2000-cell table every time a page loads.

Method 2: Store the table in an SQL database.
+Only loads the needed rows or columns, reducing execution time.
-Must create custom SQL lookup code for every page.


Is there really a big speed difference between these two solutions? Is there a better solution?

-David McWilliams
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

i would decide based on how often the data needs to be
updated and how much traffic we are talking about....

1. rarely updated: build the flat file once and
include it into the page
2. occasionally updated: store in a sql database, provide editing tools, and build out a flat include file whenever the data is updated.
3. frequently updated: store in a sql database and build page dynamically every time. Unless we are talking thousands of hits a day, than use method 2.

my 2cents :wink:
Post Reply