In what ways can the use of PDO statements improve the security and performance of PHP scripts?

Using PDO statements can improve the security of PHP scripts by automatically escaping input parameters, preventing SQL injection attacks. Additionally, PDO statements can enhance performance by preparing SQL queries once and executing them multiple times with different parameters, reducing the overhead of query parsing.

// Establish a PDO connection
$pdo = new PDO('mysql:host=localhost;dbname=test', 'username', 'password');

// Prepare a SQL statement
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');

// Bind parameters and execute the statement
$stmt->bindParam(':username', $username);
$stmt->execute();

// Fetch results
$results = $stmt->fetchAll();