In PHP, what is the best practice for structuring SQL queries to improve readability and maintainability?

When structuring SQL queries in PHP, it is best practice to separate the query logic from the presentation logic for improved readability and maintainability. One way to achieve this is by storing the SQL queries in separate variables or functions, making it easier to modify and debug the queries when needed.

// Define SQL query in a separate variable
$sql = "SELECT * FROM users WHERE status = 'active'";

// Execute the query
$result = mysqli_query($conn, $sql);

// Fetch data from the result set
while ($row = mysqli_fetch_assoc($result)) {
    // Process the data
}