How can the structure of each field in an SQL query result be displayed in PHP?
When executing an SQL query in PHP, the structure of each field in the query result can be displayed by using the `mysqli_fetch_field_direct` function. This function retrieves the field information for a specific field in the result set. By looping through each field in the result set and using `mysqli_fetch_field_direct`, you can access details such as the field name, type, length, and flags.
<?php
// Execute SQL query
$result = mysqli_query($conn, "SELECT * FROM table");
// Get the number of fields in the result set
$num_fields = mysqli_num_fields($result);
// Loop through each field and display its structure
for ($i = 0; $i < $num_fields; $i++) {
$field_info = mysqli_fetch_field_direct($result, $i);
echo "Field name: " . $field_info->name . "<br>";
echo "Field type: " . $field_info->type . "<br>";
echo "Field length: " . $field_info->length . "<br>";
echo "Field flags: " . $field_info->flags . "<br><br>";
}
?>