Set the field pointer of the first field (column) in the result set, then obtain the field information through mysqli_fetch_field() and output the 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 the field information of the first column ("name") mysqli_field_seek($result,0); $fieldinfo=mysqli_fetch_field($result ); printf("Field name: %s",$fieldinfo->name); echo "<br>"; printf("Table name: %s",$fieldinfo->table); echo "<br>"; printf("Field length: %d",$fieldinfo->max_length); // Release the result set mysqli_free_result($result );}mysqli_close($con);?>
The mysqli_field_seek() function sets the field pointer to the offset of the specified field.
mysqli_field_seek( result,fieldnr ) ;
parameter | describe |
---|---|
result | Required. Specifies the 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 number of fields - 1. |
Return value: | Returns TRUE if successful and FALSE if failed. |
---|---|
PHP version: | 5+ |