Are there any specific best practices to follow when including PHP files with SQL queries?

When including PHP files with SQL queries, it is important to follow best practices to ensure security and efficiency. One common best practice is to use prepared statements to prevent SQL injection attacks. Additionally, it is recommended to separate SQL queries into their own files for better organization and maintenance.

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

// Define the SQL query in a separate file
$sql_query = file_get_contents('sql_query.sql');

// Prepare and execute the SQL query using prepared statements
$stmt = $pdo->prepare($sql_query);
$stmt->execute();

// Fetch the results if needed
$results = $stmt->fetchAll();