最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
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."
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."
相关文章
- 洛克王国世界神圣狮鹫在哪 神圣狮鹫捕捉位置 10-14
- 洛克王国世界可可果树在哪里 可可果树具体位置 10-14
- 二重螺旋深渊boss怎么打 深渊boss打法教学 10-14
- 蓝色星原旅谣寒悠悠怎么样 寒悠悠角色介绍 10-14
- 蓝色星原旅谣PVP怎么玩 PVP玩法介绍 10-14
- 伊瑟宁芙涅怎么培养 宁芙涅培养攻略 10-14