What are the best practices for designing database structures to avoid complex LIKE queries in PHP?

Complex LIKE queries in PHP can be avoided by properly designing the database structure. One way to do this is by using indexing on columns that are frequently searched using LIKE queries. Additionally, breaking down data into separate tables and using relationships can help reduce the need for complex LIKE queries.

// Example of properly designing a database structure to avoid complex LIKE queries
CREATE TABLE users (
    id INT PRIMARY KEY,
    username VARCHAR(50),
    email VARCHAR(50),
    role_id INT,
    FOREIGN KEY (role_id) REFERENCES roles(id)
);

CREATE TABLE roles (
    id INT PRIMARY KEY,
    name VARCHAR(50)
);

// Indexing the username column for faster LIKE queries
CREATE INDEX idx_username ON users(username);