What are the key differences between mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_row, and mysql_fetch_object in PHP and when should each be used?

When retrieving data from a MySQL database in PHP, it's important to choose the appropriate function based on how you want to access the data. - mysql_fetch_array returns a result row as both an associative array and a numeric array. - mysql_fetch_assoc returns a result row as an associative array. - mysql_fetch_row returns a result row as a numeric array. - mysql_fetch_object returns a result row as an object. Use mysql_fetch_assoc when you want to access the data by field names, mysql_fetch_row when you want to access the data by numerical indexes, mysql_fetch_array when you want to access the data by both field names and numerical indexes, and mysql_fetch_object when you want to access the data as an object.

// Example using mysql_fetch_assoc
$result = mysql_query("SELECT * FROM table");
while ($row = mysql_fetch_assoc($result)) {
    echo $row['column1'] . ' ' . $row['column2'];
}