What are the best practices for structuring and formatting SQL queries in PHP code?

When structuring and formatting SQL queries in PHP code, it is important to use prepared statements to prevent SQL injection attacks and improve performance. Additionally, it is recommended to separate the SQL query from the PHP code for better readability and maintainability.

// Example of structuring and formatting SQL queries in PHP code

// Define the SQL query separately
$sql = "SELECT * FROM users WHERE id = :id";

// Prepare the SQL query
$stmt = $pdo->prepare($sql);

// Bind parameters
$stmt->bindParam(':id', $id, PDO::PARAM_INT);

// Execute the query
$stmt->execute();

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