PHP mysql_fetch_field() º¯Êý

¶¨ÒåºÍÓ÷¨

mysql_fetch_field() º¯Êý´Ó½á¹û¼¯ÖÐÈ¡µÃÁÐÐÅÏ¢²¢×÷Ϊ¶ÔÏ󷵻ء£

mysql_fetch_field() ¿ÉÒÔÓÃÀ´´Ó²éѯ½á¹ûÖÐÈ¡µÃ×ֶεÄÐÅÏ¢¡£Èç¹ûûÓÐÖ¸¶¨×Ö¶ÎÆ«ÒÆÁ¿£¬ÔòÌáÈ¡ÏÂÒ»¸öÉÐδ±» mysql_fetch_field() È¡µÃµÄ×ֶΡ£

¸Ãº¯Êý·µ»ØÒ»¸ö°üº¬×Ö¶ÎÐÅÏ¢µÄ¶ÔÏó¡£

±»·µ»ØµÄ¶ÔÏóµÄÊôÐÔΪ£º

  • name - ÁÐÃû
  • table - ¸ÃÁÐËùÔڵıíÃû
  • max_length - ¸ÃÁÐ×î´ó³¤¶È
  • not_null - 1£¬Èç¹û¸ÃÁв»ÄÜΪ NULL
  • primary_key - 1£¬Èç¹û¸ÃÁÐÊÇ primary key
  • unique_key - 1£¬Èç¹û¸ÃÁÐÊÇ unique key
  • multiple_key - 1£¬Èç¹û¸ÃÁÐÊÇ non-unique key
  • numeric - 1£¬Èç¹û¸ÃÁÐÊÇ numeric
  • blob - 1£¬Èç¹û¸ÃÁÐÊÇ BLOB
  • type - ¸ÃÁеÄÀàÐÍ
  • unsigned - 1£¬Èç¹û¸ÃÁÐÊÇÎÞ·ûºÅÊý
  • zerofill - 1£¬Èç¹û¸ÃÁÐÊÇ zero-filled

Óï·¨

mysql_fetch_field(data,field_offset)
²ÎÊý ÃèÊö
data ±ØÐ衣ҪʹÓõÄÊý¾ÝÖ¸Õë¡£¸ÃÊý¾ÝÖ¸ÕëÊÇ´Ó mysql_query() ·µ»ØµÄ½á¹û¡£
field_offset ±ØÐè¡£¹æ¶¨´ÓÄĸö×ֶοªÊ¼¡£0 ָʾµÚÒ»¸ö×ֶΡ£Èç¹ûδÉèÖã¬ÔòÈ¡»ØÏÂÒ»¸ö×ֶΡ£

ÌáʾºÍ×¢ÊÍ

×¢ÊÍ£º±¾º¯Êý·µ»ØµÄ×Ö¶ÎÃûÊÇÇø·Ö´óСдµÄ¡£

Àý×Ó

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$db_selected = mysql_select_db("test_db",$con);

$sql = "SELECT * from Person";
$result = mysql_query($sql,$con);

while ($property = mysql_fetch_field($result))
  {
  echo "Field name: " . $property->name . "<br />";
  echo "Table name: " . $property->table . "<br />";
  echo "Default value: " . $property->def . "<br />";
  echo "Max length: " . $property->max_length . "<br />";
  echo "Not NULL: " . $property->not_null . "<br />"; 
  echo "Primary Key: " . $property->primary_key . "<br />";
  echo "Unique Key: " . $property->unique_key . "<br />"; 
  echo "Mutliple Key: " . $property->multiple_key . "<br />";
  echo "Numeric Field: " . $property->numeric . "<br />";
  echo "BLOB: " . $property->blob . "<br />";
  echo "Field Type: " . $property->type . "<br />";
  echo "Unsigned: " . $property->unsigned . "<br />";
  echo "Zero-filled: " . $property->zerofill . "<br /><br />"; 
  }

mysql_close($con);
?>

Êä³ö£º

Field name: LastName
Table name: Person
Default value: 
Max length: 8
Not NULL: 0
Primary Key: 0
Unique Key: 0
Mutliple Key: 0
Numeric Field: 0
BLOB: 0
Field Type: string
Unsigned: 0
Zero-filled: 0

Field name: FirstName
Table name: Person
Default value: 
Max length: 7
Not NULL: 0
Primary Key: 0
Unique Key: 0
Mutliple Key: 0
Numeric Field: 0
BLOB: 0
Field Type: string
Unsigned: 0
Zero-filled: 0

Field name: City
Table name: Person
Default value: 
Max length: 9
Not NULL: 0
Primary Key: 0
Unique Key: 0
Mutliple Key: 0
Numeric Field: 0
BLOB: 0
Field Type: string
Unsigned: 0
Zero-filled: 0

Field name: Age
Table name: Person
Default value: 
Max length: 2
Not NULL: 0
Primary Key: 0
Unique Key: 0
Mutliple Key: 0
Numeric Field: 1
BLOB: 0
Field Type: int
Unsigned: 0
Zero-filled: 0
VUE