What are the potential pitfalls of using the MySQL extension in PHP, and what alternatives are recommended?

Using the MySQL extension in PHP is deprecated and has been removed in newer versions of PHP. This can lead to security vulnerabilities and compatibility issues. It is recommended to use alternative extensions such as MySQLi or PDO for interacting with MySQL databases in PHP.

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

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