一聚教程网:一个值得你收藏的教程网站

热门教程

PHP4 与 MySQL 数据库操作函数详解(3)

时间:2022-07-02 09:33:57 编辑:袖梨 来源:一聚教程网

7) 数据库信息函数(2个):
1、mysql_fetch_field()
格式:object mysql_fetch_field(int query , int [field_offset]);
返回1个对象,即一哈希表,下标有:
table : 表名
name : 字段名
max_length : 该字段的最大长度
not_null : 字段为not null则返回1,否则返回0
primary_key : 字段为primary key则返回1,否则返回0
unique_key : 字段为unique key则返回1,否则返回0
multiple_key : 字段为非unique key则返回1,否则返回0
numeric : 字段为numeric则返回1,否则返回0
blob : 字段为blob则返回1,否则返回0
type : 字段的类型
unsigned : 字段为unsigned则返回1,否则返回0
zerofill : 字段为zero filled则返回1,否则返回0
引用格式为:对象名->下标名
使用此函数可以得到表名、字段名、类型.......
例子:
$query = mysql_query($sql , $connect);
while($object = mysql_fetch_field($query))
{
echo "table name : ".$object->table."
";
echo "field name : ".$object->name."
";
echo "primary key : ".$object->primary_key."
";
echo "not null : ".$object->not_null."
";
echo "field type : ".$object->type."
";
echo "field max length : ".$object->max_length."
";
}
?>
Note : 哈希表的是从0坐标开始的,即第一个字段为哈希表中的0项。
如果我们想直接得到哈希表的第三项即第三个字段的信息,可用如下格式:
$query = mysql_query($sql , $connect);
$object = mysql_fetch_field($query , 2);
echo "table name : ".$object->table."
";
echo "field name : ".$object->name."
";
echo "primary key : ".$object->primary_key."
";
echo "not null : ".$object->not_null."
";
echo "field type : ".$object->type."
";
echo "field max length : ".$object->max_length."

热门栏目