How can database normalization principles be applied to improve the efficiency and security of user role management in PHP applications?

Issue: Database normalization principles can be applied to improve the efficiency and security of user role management in PHP applications by organizing data into separate tables to reduce redundancy and ensure data integrity.

// Example of implementing database normalization for user role management in PHP

// users table
CREATE TABLE users (
    id INT PRIMARY KEY,
    username VARCHAR(50) UNIQUE,
    password VARCHAR(255),
    email VARCHAR(100)
);

// roles table
CREATE TABLE roles (
    id INT PRIMARY KEY,
    role_name VARCHAR(50) UNIQUE
);

// user_roles table to establish many-to-many relationship between users and roles
CREATE TABLE user_roles (
    user_id INT,
    role_id INT,
    PRIMARY KEY (user_id, role_id),
    FOREIGN KEY (user_id) REFERENCES users(id),
    FOREIGN KEY (role_id) REFERENCES roles(id)
);