MySQL函式庫

mysql_fetch_field

(PHP3 , PHP4)

mysql_fetch_field ---  取得欄位資訊

語法 : object mysql_fetch_field (int result [, int field_offset])

說明 : 

傳回一包含欄位資訊的物件

mysql_fetch_field( )能用來為了獲得某些查詢的結果中欄位的資訊,如果沒有指定欄位的偏移量(offset),則無法以mysql_fetch_field( )獲得下一個欄位

回的物件其內容有 :

name—欄位名稱

          table—欄位所在的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表示欄位為數值的

          blob—1表示欄位為BLOB

          type—欄位的型態

          unsigned—1表示欄位為無記號(unsigned)

          zerofill—1表示欄位被零填滿(zero-filled)

Example :

<?php

    mysql_connect ($host, $user, $password) or die ("Could not connect");

    $result = mysql_db_query ("database", "select * from table") or die ("Query failed"); 

      # 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( )


上一頁 首頁 下一頁