Is there a recommended way to structure PHP files with SQL queries when using includes?

When using includes in PHP to separate code into different files, it's important to structure your files in a way that keeps your SQL queries organized and easily maintainable. One recommended way to do this is to create a separate file specifically for your SQL queries and include it in your main PHP files where needed. This helps keep your code clean and makes it easier to make changes to your queries without having to search through multiple files.

// db_queries.php
<?php
function get_users() {
    return "SELECT * FROM users";
}

function get_user_by_id($id) {
    return "SELECT * FROM users WHERE id = $id";
}
?>

// index.php
<?php
include 'db_queries.php';

$query = get_users();
// Execute query and process results
?>

// profile.php
<?php
include 'db_queries.php';

$user_id = 1;
$query = get_user_by_id($user_id);
// Execute query and process results
?>