What could be causing the "Call to undefined function: mysql_connect()" error in PHP?

The "Call to undefined function: mysql_connect()" error in PHP is likely caused by the fact that the MySQL extension is no longer supported in PHP versions 7.0 and above. To solve this issue, you should switch to the MySQLi or PDO extension for database connectivity.

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

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

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