Returns an array of objects representing fields (columns) in the result set, then outputs each field name, table, and maximum length:
<?php // Assume database username: root, password: 123456, database: CODERCTO $con=mysqli_connect("localhost","root","123456","CODERCTO"); 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 all fields $fieldinfo=mysqli_fetch_fields($result); foreach ($fieldinfo as $val) { printf("field Name: %s",$val->name); echo "<br>"; printf("Data table: %s",$val->table); echo "<br>"; printf("Maximum length: %d",$val->max_length); echo "<br>"; } // Release the result set mysqli_free_result( $result);}mysqli_close($con);?>
The mysqli_fetch_fields() function returns an array of objects representing fields (columns) in the result set.
mysqli_fetch_fields( result ) ;
parameter | describe |
---|---|
result | Required. Specifies the result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result(). |
Return value: | Returns an object containing field definition information. Returns FALSE if no information is available. This object has the following properties: name - column name orgname - the original column name (if an alias is specified) table - table name orgtable - the original table name (if an alias is specified) max_length - the maximum width of the field length - the field width specified in the table definition charsetnr - the character set number of the field flags - the bit flags of the field type - the data type used for the field decimals - integer field, number of digits after decimal point |
---|---|
PHP version: | 5+ |