What are the common causes of SQL syntax errors in PHP queries and how can they be fixed to ensure proper execution?

Common causes of SQL syntax errors in PHP queries include missing quotation marks around string values, incorrect table or column names, missing or misplaced commas, and using reserved keywords as identifiers without backticks. To fix these issues, always use prepared statements to prevent SQL injection and ensure proper escaping of user input.

// Example of a correct SQL query using prepared statements
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();
$results = $stmt->fetchAll();