Ghost
Platinum Coder
Much like popular online software, we can create scripts that automatically generate database tables.
This comes in handy because it allows the user to simply give us the database name / user / password / host information instead of forcing them to upload an SQL file or manually create the database (ha, could you imagine...). Software such as XenForo, MyBB, WordPress, etc all run installation queries to handle the database creation once they have the details to connect!
It's very simple 🙂
This simple query goes like this...
This easy INSERT would generate User ID 1 in forum_users. You could obviously add things like hashed password, join data, role_id, etc.
I hope this helped you! 🙂
This comes in handy because it allows the user to simply give us the database name / user / password / host information instead of forcing them to upload an SQL file or manually create the database (ha, could you imagine...). Software such as XenForo, MyBB, WordPress, etc all run installation queries to handle the database creation once they have the details to connect!
It's very simple 🙂
SQL:
CREATE TABLE IF NOT EXISTS forum_users
(id int NOT NULL AUTO_INCREMENT,
username varchar(50) NOT NULL,
email varchar(255) NOT NULL,
UNIQUE(email),
UNIQUE(username),
PRIMARY KEY(id))
This simple query goes like this...
- Create the table 'forum_users' if it does not exist already in the database
- Create column 'id' ~ Cannot be NULL, also auto increments by default
- Create column 'username' ~ Cannot be NULL, is 50 chars max
- Create column 'email' ~ Cannot be NULL, is 255 chars max
- Make the username & email columns UNIQUE, to avoid duplicates
- Make the id column a PRIMARY KEY for indexing & unique id purposes
SQL:
INSERT INTO forum_users (username, email) VALUES ('Administrator', '[email protected]')
I hope this helped you! 🙂