What are the potential pitfalls of using the deprecated mysql_* extension in PHP and what are the recommended alternatives?

Using the deprecated mysql_* extension in PHP can pose security risks and compatibility issues with newer versions of PHP. It is recommended to switch to either the MySQLi or PDO extensions, which offer more secure and flexible ways to interact with databases.

// Using MySQLi extension
$mysqli = new mysqli("localhost", "username", "password", "database");

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

// Using PDO extension
try {
    $pdo = new PDO("mysql:host=localhost;dbname=database", "username", "password");
} catch (PDOException $e) {
    die("Connection failed: " . $e->getMessage());
}