Are there any best practices for formatting SQL queries in PHP to improve readability and functionality?

When writing SQL queries in PHP, it is important to properly format the queries for readability and functionality. One best practice is to use prepared statements to prevent SQL injection attacks and improve performance. Additionally, breaking long queries into multiple lines and using indentation can make the code easier to read and maintain.

// Example of formatting SQL query in PHP using prepared statements

// Establish a database connection
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// Prepare the SQL query
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");

// Bind parameters
$stmt->bindParam(':username', $username, PDO::PARAM_STR);

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

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