What are the advantages of using PHP5 PDO over traditional MySQL queries in PHP development?

Using PHP5 PDO over traditional MySQL queries in PHP development offers several advantages such as improved security through prepared statements, support for multiple database drivers, and easier error handling. PDO also provides a more consistent and object-oriented approach to database interactions.

// Using PHP5 PDO to connect to a MySQL database
$dsn = 'mysql:host=localhost;dbname=mydatabase';
$username = 'username';
$password = 'password';

try {
    $pdo = new PDO($dsn, $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    // Perform database operations using PDO
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}