PHP函数mysql_fetch_field介绍
定义和用法
mysql_fetch_field() 函数从结果集中取得列信息并作为对象返回。
mysql_fetch_field() 可以用来从查询结果中取得字段的信息。如果没有指定字段偏移量,则提取下一个尚未被 mysql_fetch_field() 取得的字段。
该函数返回一个包含字段信息的对象。
被返回的对象的属性为:
name - 列名
table - 该列所在的表名
max_length - 该列最大长度
not_null - 1,如果该列不能为 NULL
primary_key - 1,如果该列是 primary key
unique_key - 1,如果该列是 unique key
multiple_key - 1,如果该列是 non-unique key
numeric - 1,如果该列是 numeric
blob - 1,如果该列是 BLOB
type - 该列的类型
unsigned - 1,如果该列是无符号数
zerofill - 1,如果该列是 zero-filled
语法
mysql_fetch_field(data,field_offset)
提示和注释
注释:本函数返回的字段名是区分大小写的。
例子
<?php$con = mysql_connect("localhost", "hello", "321");if (!$con) { die(Could not connect: . mysql_error()); }$db_selected = mysql_select_db("test_db",$con);$sql = "SELECT * from Person";$result = mysql_query($sql,$con);while ($property = mysql_fetch_field($result)) { echo "Field name: " . $property->name . "<br />"; echo "Table name: " . $property->table . "<br />"; echo "Default value: " . $property->def . "<br />"; echo "Max length: " . $property->max_length . "<br />"; echo "Not NULL: " . $property->not_null . "<br />"; echo "Primary Key: " . $property->primary_key . "<br />"; echo "Unique Key: " . $property->unique_key . "<br />"; echo "Mutliple Key: " . $property->multiple_key . "<br />"; echo "Numeric Field: " . $property->numeric . "<br />"; echo "BLOB: " . $property->blob . "<br />"; echo "Field Type: " . $property->type . "<br />"; echo "Unsigned: " . $property->unsigned . "<br />"; echo "Zero-filled: " . $property->zerofill . "<br /><br />"; }mysql_close($con);?>
输出:
Field name: LastNameTable name: PersonDefault value: Max length: 8Not NULL: 0Primary Key: 0Unique Key: 0Mutliple Key: 0Numeric Field: 0BLOB: 0Field Type: stringUnsigned: 0Zero-filled: 0Field name: FirstNameTable name: PersonDefault value: Max length: 7Not NULL: 0Primary Key: 0Unique Key: 0Mutliple Key: 0Numeric Field: 0BLOB: 0Field Type: stringUnsigned: 0Zero-filled: 0Field name: CityTable name: PersonDefault value: Max length: 9Not NULL: 0Primary Key: 0Unique Key: 0Mutliple Key: 0Numeric Field: 0BLOB: 0Field Type: stringUnsigned: 0Zero-filled: 0Field name: AgeTable name: PersonDefault value: Max length: 2Not NULL: 0Primary Key: 0Unique Key: 0Mutliple Key: 0Numeric Field: 1BLOB: 0Field Type: intUnsigned: 0Zero-filled: 0
本文出自:琅枫个人博客。如需转载请注明出处!
本文出处:"https://www.langfujun.top/function/413.html"
如果您觉得文章对你有帮助,可以进行打赏。
打赏多少,您高兴就行,谢谢您对琅枫博客的支持! ~(@^_^@)~
微信打赏

支付宝打赏
