What are some potential pitfalls when using the old MySQL extension in PHP and what are some alternatives?

Using the old MySQL extension in PHP can lead to security vulnerabilities and compatibility issues as it has been deprecated since PHP 5.5 and removed in PHP 7. To avoid these pitfalls, it is recommended to switch to MySQLi (MySQL Improved) extension or PDO (PHP Data Objects) for database operations.

// 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");