What are the advantages of switching from the mysql_* extension to mysqli_* or PDO in PHP?

Switching from the mysql_* extension to mysqli_* or PDO in PHP offers several advantages, including improved security features such as prepared statements to prevent SQL injection attacks, support for transactions, and enhanced error handling capabilities. Additionally, mysqli_* and PDO provide object-oriented interfaces, making it easier to work with databases and allowing for better code organization and maintainability.

// Using mysqli_* extension
$mysqli = new mysqli('localhost', 'username', 'password', 'database');

if ($mysqli->connect_error) {
    die('Connection failed: ' . $mysqli->connect_error);
}

// Using PDO
$pdo = new PDO('mysql:host=localhost;dbname=database', 'username', 'password');

if (!$pdo) {
    die('Connection failed');
}