What resources or tutorials would you recommend for someone struggling with PHP syntax for SQL queries?

When struggling with PHP syntax for SQL queries, it can be helpful to refer to online resources and tutorials that provide clear explanations and examples. Websites like W3Schools, PHP.net, and Stack Overflow offer comprehensive guides and forums where you can find solutions to common syntax errors and best practices for writing SQL queries in PHP.

<?php
// Example PHP code snippet demonstrating correct syntax for a SQL query using PDO

try {
    $pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id");
    $stmt->bindParam(':id', $userId, PDO::PARAM_INT);
    $stmt->execute();

    $result = $stmt->fetchAll(PDO::FETCH_ASSOC);

    foreach ($result as $row) {
        echo $row['username'] . "<br>";
    }
} catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}
?>