Easy Tutorial
❮ Func Mysqli Fetch Fields Func Filesystem Touch ❯

PHP mysqli_fetch_field_direct() Function

PHP MySQLi Reference Manual

Returns the meta-data of a single field (column) in a result set and outputs the field name, table, and maximum length:

<?php 
// Assume database username: root, password: 123456, database: tutorialpro 
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

$sql = "SELECT name, url FROM websites ORDER BY alexa";

if ($result = mysqli_query($con, $sql))
{
    // Get information about the "name" field
    $fieldinfo = mysqli_fetch_field_direct($result, 1);

    printf("Field Name: %s", $fieldinfo->name);
    echo "<br>";
    printf("Table: %s", $fieldinfo->table);
    echo "<br>";
    printf("Maximum Length: %d", $fieldinfo->max_length);

    // Free the result set
    mysqli_free_result($result);
}

mysqli_close($con);
?>

Definition and Usage

The mysqli_fetch_field_direct() function retrieves the meta-data of a single field (column) in a result set and returns it as an object.


Syntax

Parameter Description
result Required. Specifies a result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result().
fieldnr Required. Specifies the field number. Must be between 0 and the number of fields - 1.

Technical Details

Return Value: Returns an object containing field definition information. Returns FALSE if no information is available. The object has the following properties: name - column name<br> orgname - original column name (if an alias was specified)<br> table - table name<br> orgtable - original table name (if an alias was specified)<br> def - the default value of the field<br> max_length - the maximum width of the field<br> length - the width of the field as specified in the table definition<br> charsetnr - the character set number of the field<br> flags - bit flags for the field<br> type - data type used for the field<br> decimals - the number of decimals for integer fields
PHP Version: 5+
--- ---
❮ Func Mysqli Fetch Fields Func Filesystem Touch ❯