I’m designing a database in MySQL and PHP for a basic CMS. The CMS will have a front end which will allow sorting and searching. The backend will allow authorized users to upload files.
I’m using PHPMyAdmin and I’d like help setting up my database.
I am open to answers explaining various MySQL datatypes and what they are good for as well . Use common database fields as examples please.
Below is a list of what I’d like. What’s missing and what datatypes do I need to use?
Resources (For my files)
- file_id
- filename (Files are presorted and display names and paths are derived
from here.)- file_type (PDF | AUDIO | VIDEO | PHOTO [Also used to generate file
urls])- upload date (timestamp in PHP or MySQL)
- uploaded_by (User ID from Users table)
- event (event_id from Events table, optional)
Users (User accounts – for admin access and maybe a notification list)
- user_id
- first_name
- last_name
- password
- phone_number (optional)
- permissions_level (read only, upload)
- creation_date
Events
- event_id
- event_name
- event_location
- event_date
- event_description
- entry_date
What I would take:
Resources (For my files)
Users (User accounts – for admin access and maybe a notification list)
Events
When you have set up your database and input some dummy data, you can run a simple statement through phpmyadmin that will tell you, what MySQL would take for that exact dummy data:
In the column
Optimal_fieldtypeyou will find what MySQL tells you to take. But you should not take that exact fieldtype. It will tell you very often to take a ENUM but most of the time you add random data so you have to take a VARCHAR in that cases the columnMax_lengthwill give you a hint on how long it should be. But on all VARCHAR fields you should add additonal space depending on how long you expect the values to be. Take in consideration that even a name can be longer than 50 chars.