What are the differences between prepared statements in mysqli and pdo in PHP?
Prepared statements in mysqli and PDO are similar in that they both allow for the use of placeholders to prevent SQL injection attacks. However, PDO is more versatile as it supports multiple database types, while mysqli is specific to MySQL databases. PDO also has a more consistent interface and error handling compared to mysqli.
// Using prepared statements with PDO
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->bindParam(':username', $username);
$stmt->execute();
$results = $stmt->fetchAll();