PHP mysqli_fetch_field () function
Returns the result set to the next field (column) and the output of each field name, and the maximum length of the form:
<?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)) { // 获取所有列的字段信息 while ($fieldinfo = mysqli_fetch_field($result)) { printf("字段名: %s\n", $fieldinfo->name); echo "<br>"; printf("数据表: %s\n", $fieldinfo->table); echo "<br>"; printf("最大长度: %d\n", $fieldinfo->max_length); echo "<br>"; } // 释放结果集 mysqli_free_result($result); } mysqli_close($con); ?>
Definition and Usage
mysqli_fetch_field () function Fetch next field (column) from the results, and return as an object.
grammar
mysqli_fetch_field( result ) ;
参数 | 描述 |
---|---|
result | 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 |
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