What is the recommended alternative to using mysql_fetch_array with MYSQL_ASSOC in PHP?

The recommended alternative to using mysql_fetch_array with MYSQL_ASSOC in PHP is to use the mysqli_fetch_assoc function. This function fetches a row from a result set as an associative array. It provides a more secure and efficient way to retrieve data from a MySQL database in PHP.

// Connect to MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Query the database
$result = $mysqli->query("SELECT * FROM table");

// Fetch data as associative array
while ($row = $result->fetch_assoc()) {
    // Process data here
}

// Close connection
$mysqli->close();