PHP mysqli_fetch_field_direct () function
Returns a single result set fields (columns) of meta-data, and outputs the field name, and the maximum length of the table:
<?php // 假定数据库用户名:root,密码:123456,数据库:w3big $con=mysqli_connect("localhost","root","123456","w3big"); if (mysqli_connect_errno($con)) { echo "连接 MySQL 失败: " . mysqli_connect_error(); } $sql="SELECT name,url FROM websites ORDER BY alexa"; if ($result=mysqli_query($con,$sql)) { // 获取字段 "name" 的信息 $fieldinfo=mysqli_fetch_field_direct($result,1); printf("字段名: %s",$fieldinfo->name); echo "<br>"; printf("数据表: %s",$fieldinfo->table); echo "<br>"; printf("最大长度: %d",$fieldinfo->max_length); // 释放结果集 mysqli_free_result($result); } mysqli_close($con); ?>
Definition and Usage
mysqli_fetch_field_direct () function to obtain a single centralized field from the results (column) of meta-data, and return as an object.
grammar
mysqli_fetch_field_direct( result,fieldnr ) ;
参数 | 描述 |
---|---|
result | 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 |
fieldnr | 必需。规定字段号。必须介于 0 和 字段数-1 之间。 |
technical details
return value: | Returns an object that contains field definition information. If no information is available it returns FALSE. This object has the following properties:
|
---|---|
PHP version: | 5+ |
PHP MySQLi Reference Manual