What are the potential pitfalls of using the mysql_connect function in PHP and how can they be addressed?

Potential pitfalls of using the mysql_connect function in PHP include deprecated usage (as it is no longer recommended), security vulnerabilities, and lack of support for newer versions of MySQL. To address these issues, it is recommended to use the mysqli or PDO extension for connecting to a MySQL database in PHP.

// Using mysqli extension to connect to a MySQL database
$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);
}