Why is it recommended to switch from using mysql_* functions to mysqli_ or PDO in PHP?

It is recommended to switch from using mysql_* functions to mysqli_ or PDO in PHP because the mysql_* functions are deprecated as of PHP 5.5 and removed in PHP 7. Additionally, mysqli_ and PDO offer more features, improved security, and better performance compared to the older mysql_* functions.

// Using mysqli
$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");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);