How can the topic and text tables be effectively linked in a PHP forum database?

To effectively link the topic and text tables in a PHP forum database, you can use a foreign key constraint in the text table that references the primary key in the topic table. This ensures that each text entry is associated with a specific topic.

CREATE TABLE topic (
    id INT PRIMARY KEY,
    title VARCHAR(255)
);

CREATE TABLE text (
    id INT PRIMARY KEY,
    content TEXT,
    topic_id INT,
    FOREIGN KEY (topic_id) REFERENCES topic(id)
);