In what ways can PDO be beneficial for database interactions in PHP compared to mysqli_*?

PDO can be beneficial for database interactions in PHP compared to mysqli_* because it provides a consistent interface for accessing different types of databases, supports prepared statements for preventing SQL injection attacks, and allows for easier code maintenance and portability.

// Using PDO for database interactions
try {
    $pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');
    $stmt = $pdo->prepare('SELECT * FROM users WHERE id = :id');
    $stmt->bindParam(':id', $userId, PDO::PARAM_INT);
    $stmt->execute();
    $user = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    echo 'Error: ' . $e->getMessage();
}