PHP mysqli_fetch_fields () function
Returns an array of result objects concentrated on behalf of the fields (columns), 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)) { // 获取所有字段的信息 $fieldinfo=mysqli_fetch_fields($result); foreach ($fieldinfo as $val) { printf("字段名: %s",$val->name); echo "<br>"; printf("数据表: %s",$val->table); echo "<br>"; printf("最大长度: %d",$val->max_length); echo "<br>"; } // 释放结果集 mysqli_free_result($result); } mysqli_close($con); ?>
Definition and Usage
() Function returns an array result set representative of the field (column) objects mysqli_fetch_fields.
grammar
mysqli_fetch_fields( 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