How can the error message "Fatal error: Call to undefined function mysql_connect()" be resolved in PHP scripts?

The error "Fatal error: Call to undefined function mysql_connect()" occurs when the MySQL extension is not enabled in PHP. To resolve this issue, you can switch to using the MySQLi or PDO extension for connecting to a MySQL database instead.

// Example using MySQLi extension
$mysqli = new mysqli('localhost', 'username', 'password', 'database_name');
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}