Use php to get table field information

WBOY
Release: 2016-07-25 09:11:46
Original
1514 people have browsed it

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

举例:

  1. $link=mysql_connect("localhost","root","root") or die("couldn't connect:".mysql_error());
  2. mysql_select_db("rorely");
  3. $result=mysql_query("select * from test")or die("query failed:".mysql_error());
  4. for($i=0;$i $meta=mysql_fetch_field($result);
  5. if(!$meta) echo "没有字段信息.
    ";
  6. echo "
    ".$meta->name."<br>".$meta->type."<br>".$meta->max_length."<hr>
    ";
  7. }
  8. mysql_free_result($result);
  9. ?>
复制代码

结果如下: id int 2

name string 4

age int 2

sex string 6

address string 16



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template