What could be the potential reasons for the "Call to undefined function mysql_connect()" error in PHP?

The "Call to undefined function mysql_connect()" error in PHP occurs when the MySQL extension is not enabled or deprecated in the PHP configuration. To solve this issue, you can switch to using MySQLi or PDO extensions for connecting to a MySQL database, as they are more modern and secure options.

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

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

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