What is the significance of using MYSQL_ASSOC when fetching data from a MySQL database in PHP?

When fetching data from a MySQL database in PHP, using MYSQL_ASSOC as the second parameter in the mysqli_fetch_array() function is significant because it retrieves the data as an associative array with column names as keys. This makes it easier to access specific columns of the result set by their names rather than numerical indices.

// Connect to MySQL database
$connection = mysqli_connect('localhost', 'username', 'password', 'database');

// Fetch data from database
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);

// Fetch data as an associative array
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
    // Access data by column names
    echo $row['column_name'];
}

// Close database connection
mysqli_close($connection);