mysql_fetch_field
Get column information from the result set and return it as an object.
Function name: mysql_fetch_field()
Applicable version: PHP 4, PHP 5, PHP 7
Usage: The mysql_fetch_field() function is used to obtain information about fields from the result set.
grammar:
mixed mysql_fetch_field ( resource $result [, int $field_offset = 0 ] )
parameter:
Return value:
Example:
// 创建数据库连接$conn = mysql_connect("localhost", "username", "password"); mysql_select_db("database_name", $conn); // 执行查询$result = mysql_query("SELECT * FROM table_name", $conn); // 获取第一个字段的信息$field = mysql_fetch_field($result, 0); // 打印字段信息echo "字段名:" . $field->name . "<br>"; echo "字段类型:" . $field->type . "<br>"; echo "字段长度:" . $field->length . "<br>"; echo "字段标志:" . $field->flags . "<br>"; echo "字段自动增长:" . $field->flags . "<br>"; // 释放结果集mysql_free_result($result); // 关闭数据库连接mysql_close($conn);
Notes: