search
Homephp教程php手册PHP4与MySQL数据库操作函数详解(五)

 

(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
  
  
引用格式为:对象名->下标名
  
  
使用此函数可以得到表名、字段名、类型.......
  
  
例子:
  
  php
  $query = mysql_query($sql , $connect);
  while($object = mysql_fetch_field($query))
  {
  echo "table name : ".$object->table."br
>";
  echo "field name : ".$object->name."br>";
  echo "primary key : ".$object->primary_key."br>";
  echo "not null : ".$object->not_null."br>";
  echo "field type : ".$object->type."br>";
  echo "field max length : ".$object->max_length."br>";
  }
  ?>
  
  Note : 哈希表的是从0坐标开始的,即第一个字段为哈希表中的0项。
  
如果我们想直接得到哈希表的第三项即第三个字段的信息,可用如下格式:
  php
  $query = mysql_query($sql , $connect);
  $object = mysql_fetch_field($query , 2);
  echo "table name : ".$object->table."br
>";
  echo "field name : ".$object->name."br>";
  echo "primary key : ".$object->primary_key."br>";
  echo "not null : ".$object->not_null."br>";
  echo "field type : ".$object->type."br>";
  echo "field max length : ".$object->max_length."br>";
  ?>
  
  其实这也可以通过下面这个函数来达到同样的目的。
  
  2
mysql_field_seek()
  
格式:int mysql_field_seek(int $query , int field_offset);
  
  
将游标移到指定的字段上。
  
例子:
  
  php
  $query = mysql_query($sql , $connect);
  $seek = mysql_field_seek($query , 2);
  $object = mysql_fetch_field($query);
  echo "table name : ".$object->table."br
>";
  echo "field name : ".$object->name."br>";
  echo "primary key : ".$object->primary_key."br>";
  echo "not null : ".$object->not_null."br>";
  echo "field type : ".$object->type."br>";
  echo "field max length : ".$object->max_length."br>";
  ?>
  
  这样也达到与上例同样的要求。
  
  



Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment