What are the advantages of using mysqli_ or PDO extensions over the deprecated mysql_ extension in PHP?

The mysql_ extension in PHP is deprecated and should not be used due to security vulnerabilities and lack of support. It is recommended to use either the mysqli_ or PDO extensions for database operations in PHP as they offer improved security features, support for prepared statements, and better overall performance.

// Using mysqli extension
$mysqli = new mysqli('localhost', 'username', 'password', 'database_name');
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Using PDO extension
$pdo = new PDO('mysql:host=localhost;dbname=database_name', 'username', 'password');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);