What are the best practices for managing and updating content in a database using PHP for a website with multiple pages?

Managing and updating content in a database for a website with multiple pages can be efficiently done by creating a separate PHP file to handle database operations. This file can be included in each page where content needs to be displayed or updated. By using functions to retrieve, update, and insert data into the database, the code can be kept clean and organized.

<?php
// Include the database connection file
include 'db_connection.php';

// Function to retrieve content from the database
function get_content($page_id) {
    global $conn;
    $sql = "SELECT content FROM pages WHERE page_id = $page_id";
    $result = $conn->query($sql);
    $content = $result->fetch_assoc();
    return $content['content'];
}

// Function to update content in the database
function update_content($page_id, $new_content) {
    global $conn;
    $sql = "UPDATE pages SET content = '$new_content' WHERE page_id = $page_id";
    $conn->query($sql);
}
?>