mysql_fetch_field

(PHP 4, PHP 5)

mysql_fetch_field 锟接斤拷锟斤拷锟斤拷锟饺★拷锟斤拷锟斤拷锟较拷锟斤拷锟轿拷锟斤拷蠓祷锟�

说锟斤拷

mysql_fetch_field ( resource $result [, int $field_offset ] ) : object

锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟街讹拷锟斤拷息锟侥讹拷锟斤拷

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

Note: 锟剿猴拷锟斤拷锟斤拷锟截碉拷锟街讹拷锟斤拷锟斤拷小写锟斤拷锟斤拷锟斤拷

Example #1 mysql_fetch_field()

<?php
mysql_connect
('localhost:3306'$user$password)
    or die(
"Could not connect: " mysql_error());
mysql_select_db("database");
$result mysql_query("select * from table")
    or die(
"Query failed: " mysql_error());
/* get column metadata */
$i 0;
while (
$i mysql_num_fields($result)) {
    echo 
"Information for column $i:<br />\n";
    
$meta mysql_fetch_field($result);
    if (!
$meta) {
        echo 
"No information available<br />\n";
    }
    echo 
"<pre>
blob:         
$meta->blob
max_length:   
$meta->max_length
multiple_key: 
$meta->multiple_key
name:         
$meta->name
not_null:     
$meta->not_null
numeric:      
$meta->numeric
primary_key:  
$meta->primary_key
table:        
$meta->table
type:         
$meta->type
unique_key:   
$meta->unique_key
unsigned:     
$meta->unsigned
zerofill:     
$meta->zerofill
</pre>"
;
    
$i++;
}
mysql_free_result($result);
?>

锟轿硷拷 mysql_field_seek()锟斤拷

锟斤拷锟斤拷

result

resource 锟酵的斤拷锟斤拷锟斤拷锟斤拷私锟斤拷锟斤拷锟斤拷锟皆讹拷 mysql_query() 锟侥碉拷锟矫★拷

field_offset

The numerical field offset. If the field offset is not specified, the next field that was not yet retrieved by this function is retrieved. The field_offset starts at 0.

锟斤拷锟斤拷值

Returns an object containing field information. The properties of the object are:

  • name - column name
  • table - name of the table the column belongs to
  • max_length - maximum length of the column
  • not_null - 1 if the column cannot be NULL
  • primary_key - 1 if the column is a primary key
  • unique_key - 1 if the column is a unique key
  • multiple_key - 1 if the column is a non-unique key
  • numeric - 1 if the column is numeric
  • blob - 1 if the column is a BLOB
  • type - the type of the column
  • unsigned - 1 if the column is unsigned
  • zerofill - 1 if the column is zero-filled

锟斤拷锟斤拷

Example #2 mysql_fetch_field() example

<?php
$conn 
mysql_connect('localhost''mysql_user''mysql_password');
if (!
$conn) {
    die(
'Could not connect: ' mysql_error());
}
mysql_select_db('database');
$result mysql_query('select * from table');
if (!
$result) {
    die(
'Query failed: ' mysql_error());
}
/* get column metadata */
$i 0;
while (
$i mysql_num_fields($result)) {
    echo 
"Information for column $i:<br />\n";
    
$meta mysql_fetch_field($result$i);
    if (!
$meta) {
        echo 
"No information available<br />\n";
    }
    echo 
"<pre>
blob:         
$meta->blob
max_length:   
$meta->max_length
multiple_key: 
$meta->multiple_key
name:         
$meta->name
not_null:     
$meta->not_null
numeric:      
$meta->numeric
primary_key:  
$meta->primary_key
table:        
$meta->table
type:         
$meta->type
unique_key:   
$meta->unique_key
unsigned:     
$meta->unsigned
zerofill:     
$meta->zerofill
</pre>"
;
    
$i++;
}
mysql_free_result($result);
?>

注锟斤拷

Note: 锟剿猴拷锟斤拷锟斤拷锟截碉拷锟街讹拷锟斤拷锟斤拷小写锟斤拷锟斤拷锟斤拷

锟轿硷拷

  • mysql_field_seek() - 锟斤拷锟斤拷锟斤拷锟斤拷械锟街革拷锟斤拷瓒ㄎ拷贫锟斤拷锟斤拷侄锟狡拷锟斤拷锟�