PHP mysqli_fetch_field() Function
PHP mysqli_fetch_field() Function
The PHP mysqli_fetch_field() function returns an object containing information about one field of a result set.
Syntax
mysqli_fetch_field(result)
Parameter Values
| Parameter | Description |
|---|---|
| result | Required. Specifies the result set returned by the last mysqli_query() or mysqli_store_result() call |
Return Value
Returns an object with the following properties:
- name: The name of the column
- orgname: Original column name if an alias was specified
- table: Name of the table the column is in
- orgtable: Original table name if an alias was specified
- def: Default value for the column
- db: Database the column is in
- catalog: Catalog the column is in
- max_length: Maximum length of the column
- length: Length of the column
- charsetnr: Character set number for the column
- flags: Flags associated with the column
- type: Type of the column
- decimals: Number of decimals
Example
<?php
// Create connection
$conn = new mysqli("localhost", "username", "password", "database");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row. " - Name: " . $row. " " . $row. "
";
}
} else {
echo "0 results";
}
$conn->close();
?>
Related Tutorials
YouTip