Building a User Login System in PHP with OOP pt.III

KolaKachi
This entry is part 24 of 24 in the series PHP Object-Oriented Programming(OOP) Crash Course

Welcome back to our course project example! In this session, we’ll create a PHP database class to interact with our MySQL database. We will be working with MYSQL workbench. Follow along with the step-by-step guide to understand the process.

Step 1: Launch MySQL Workbench

Open MySQL Workbench on your computer. If you don’t have it installed, you can download it from the official MySQL website.

Step 2: Connect to a Database Server

  1. Click on the “+” icon next to “MySQL Connections” to set up a new connection.
  2. Enter the connection details, including the connection name, connection method, hostname (usually localhost), username, and password. Click “Test Connection” to ensure the details are correct, and then click “OK” to establish the connection.

Step 3: Creating a New Database

  1. In the Navigator (top bar), you’ll see an option for “Database.” click on it.
  2. Enter the name of the database as “users” and click “Apply.”
  3. Once applied, click on the “Apply” button again to execute the SQL statement and create the database.

Step 4: Designing the Users Table

  1. In the Navigator, under the newly created oop_course_db database, right-click on “Tables” and choose “Create Table…”.
  2. In the name field add users as the name of the table.
  3. In the “Columns” tab, add the following fields:
    • id:
      • Data Type: INT
      • Check “NN” (Not Null)
      • Check “AI” (Auto-Increment)
      • Check “PK” (Primary Key)
    • username:
      • Data Type: VARCHAR(20)
      • Check “NN” (Not Null)
    • email:
      • Data Type: VARCHAR(100)
      • Check “NN” (Not Null)
      • Check “UQ” (Unique)
    • password:
      • Data Type: VARCHAR(64)
      • Check “NN” (Not Null)
    • gender:
      • Data Type: VARCHAR(6)
      • Check “NN” (Not Null)
    • date:
      • Data Type: DATETIME
      • Check “NN” (Not Null)
  4. Click on the “Apply” button to save the table structure.

Step 5: Review and Apply Changes

  1. Ensure that the script aligns with the specifications provided above.
  2. Click on the “Apply” button to execute the SQL script and create the users table.

Congratulations! You’ve successfully created a MySQL database named oop_course_db with a table named users. The table is structured to store user information with fields such as id, username, email, password, gender, and date. In the next article we’ll explore how to implement and test reading from the database using this class. Stay tuned!

Series Navigation<< Building a User Login System in PHP with OOP pt.II

Leave a Reply

Your email address will not be published. Required fields are marked *