views:

147

answers:

2

I'm just about to expand the functionality of our own CMS but was thinking of restructuring the database to make it simpler to add/edit data types and values.

Currently, the CMS is quite flat - the CMS requires a field in the database for every type of stored value (manually created).

The first option that comes to mind is simply a table which keeps the data types (ie: Address 1, Suburb, Email Address etc) and another table which holds values for each of these data types. Just like how Wordpress keeps values in the 'options' table, PHP serialize would be used to store an array of values.

The second option is how Drupal works, the CMS creates tables for every data type. Unlike Wordpress, this can be a bit of an overkill but really useful for SQL queries when ordering and grouping by a particular value.

What's everyone's thoughts?

+2  A: 

In my opinion, you should avoid serialization where possible. Your relational database should be relational, and thus be structured as such. This would include the 'Drupal Method', e.g. one table per data type. This also keeps your database healthy in a sense that it can be indexed en easily queried upon.

bouke
Very good point, I have already adopted the process of creating tables on the fly for the different data types. This has produced a much better system.
Dallas Clark
A: 

can you Please explain what you mean by creating a table for each datatype can you please give an example. thankyou.

Vetional_f
Sure, have one table which describes the data types (1 => Address, 2 => Phone, 3 => Website) and then you have another table which contains the values of these data types (1 => 123 Main St, Brisbane, 2 => 07 3800 0000, 3 => http://www.dallasjclark.com). To use the data types values table for many items (products, blogs, whatever it is) you add another column which has the id of the item (product, blog etc). I hope that makes sense ....
Dallas Clark