What are the deprecated MySQL functions in PHP and what alternatives should be used instead?

Several MySQL functions in PHP have been deprecated since PHP 5.5 and removed in PHP 7. They include mysql_connect(), mysql_query(), and mysql_fetch_array(). To address this issue, developers should switch to using MySQLi or PDO extensions for database interactions in PHP.

// Using MySQLi extension
$mysqli = new mysqli("localhost", "username", "password", "database");

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

$result = $mysqli->query("SELECT * FROM table");

while ($row = $result->fetch_assoc()) {
    // Process each row
}

$mysqli->close();