What are some recommended resources or documentation for handling database queries in PHP?

When handling database queries in PHP, it is important to ensure that you are using secure and efficient methods to interact with the database. One recommended resource for handling database queries in PHP is the PHP Data Objects (PDO) extension, which provides a consistent interface for accessing databases. Additionally, the MySQLi extension is another popular choice for interacting with MySQL databases in PHP.

// Using PDO to handle database queries in PHP
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);
    
    // Process the query result
    foreach ($result as $row) {
        // Do something with the row data
    }
} catch (PDOException $e) {
    echo 'Error: ' . $e->getMessage();
}