What are the potential pitfalls of using deprecated MySQL functions in PHP and how can they be avoided?

Using deprecated MySQL functions in PHP can lead to security vulnerabilities and compatibility issues with newer versions of MySQL. To avoid these pitfalls, it is recommended to switch to MySQLi or PDO for database operations.

// Connect to MySQL using MySQLi
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}