What are some best practices for structuring database tables to handle nested categories in PHP?

Nested categories in a database can be structured using a parent-child relationship, where each category can have a parent category. One common approach is to use a table with columns for category ID, category name, and parent category ID. This allows for a hierarchical structure where categories can have subcategories.

CREATE TABLE categories (
    id INT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    parent_id INT,
    FOREIGN KEY (parent_id) REFERENCES categories(id)
);