Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

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 :)

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...
  1. Create the table 'forum_users' if it does not exist already in the database
  2. Create column 'id' ~ Cannot be NULL, also auto increments by default
  3. Create column 'username' ~ Cannot be NULL, is 50 chars max
  4. Create column 'email' ~ Cannot be NULL, is 255 chars max
  5. Make the username & email columns UNIQUE, to avoid duplicates
  6. Make the id column a PRIMARY KEY for indexing & unique id purposes
So, you could create a script with PHP or your favorite language and once the user provides their db connection details, you can generate each table with the correct columns. You can even follow up a table creation with a default value!

SQL:
INSERT INTO forum_users (username, email) VALUES ('Administrator', '[email protected]')
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! :)
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom