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." ".$meta->type." ".$meta->max_length."
登录后复制 "; - }
- mysql_free_result($result);
-
- ?>
复制代码结果如下:idint2 namestring4 ageint2 sexstring6 addressstring16 |