[eluser]charlieD[/eluser]
I was wondering what people think is the best practice for storing data that isn't modified by the user - in the database or in a config-type file?
Say, for example, I have 3 user types for a website. The app acts differently depending on which kind of user you are.
I could have a user_type table like so:
Code:
user_type:
id: integer
name: varchar(30)
desc: varchar(255)
Or, I could have a UserType.class.php file like so:
Code:
<?php
class UserType
{
const STUDENT = 1;
const ASSISTANT = 2;
const TEACHER = 3;
static public $descriptions = array(
self::STUDENT => 'Student',
self::ASSISTANT => 'Teaching assistant',
self::TEACHER => 'Teacher / Tutor',
);
static public $names = array(
self::STUDENT => 'student',
self::ASSISTANT => 'assistant',
self::TEACHER => 'teacher',
);
}
Other examples are for storing things like lists, e.g. Film genres ('comedy', 'action', 'drama' etc.) that might appear in a <select> on a form - database or file?
In my eyes storing this information in a class file has a couple of advantages -
when you rebuild the database you don't lose the data or have the problem of the entries being assigned different IDs
it's easy to update from the text editor where you're working in anyway
fewer hits on the database
Would be grateful for thoughts on this and advantages/disadvantages of each approach.