最新下载
热门教程
- 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."
相关文章
- 《重返帝国凯撒最强技能组合指南:关键搭配助你称霸战场》 05-22
- 江苏医保云如何办理生育报销申请 05-22
- 阴阳师红叶竞速-前百混勾阵容搭配指南 05-22
- DeepSeek Code下载避坑指南:5个常见错误别踩 05-22
- 《吞食天地武将技能更换指南:精准调整技能组合强化战力》 05-22
- 3种方法找到 DeepSeek Code 官网入口(2026版) 05-22