php中获取字段信息,可以用到以下的函数:
mysql_fetch_field()
mysql_num_fields()
mysql_list_fields()
mysql_field_flags()
mysql_field_len()
mysql_field_name()
mysql_field_type()
mysql_field_table()
字段的属性有:
name ,table,max_length,not_null,primary_key,unique_key,multiple_key,numeric,blob,type,unsigned,zerofill
举例:
-
-
$link=mysql_connect("localhost","root","root") or die("couldn't connect:".mysql_error());
- mysql_select_db("rorely");
- $result=mysql_query("select * from test")or die("query failed:".mysql_error());
- for($i=0;$i $meta=mysql_fetch_field($result);
- if(!$meta) echo "没有字段信息.
";
- echo "
".$meta->name."<br>".$meta->type."<br>".$meta->max_length."<hr> Salin selepas log masuk ";
- }
- mysql_free_result($result);
-
- ?>
复制代码
结果如下:
id
int
2
name
string
4
age
int
2
sex
string
6
address
string
16
|