(PECL CUBRID >= 8.3.1)
cubrid_fetch_field — 從結果集中取得欄位資訊並以物件形式返回
此函式會返回一個物件,其中包含特定欄位的某些屬性。物件的屬性如下:
name欄位名稱
table欄位所屬的表格名稱
def欄位的預設值
max_length欄位的最大長度
not_null如果欄位不可為 NULL,則為 1
primary_key如果欄位是主鍵,則為 1
unique_key如果欄位是唯一鍵,則為 1
multiple_key如果欄位是非唯一鍵,則為 1
numeric若欄位為數值類型則為 1
blob若欄位為 BLOB 類型則為 1
type欄位的類型
unsigned若欄位為無號數類型則為 1
zerofill若欄位為零填充則為 1
resultresult 來自呼叫 cubrid_execute() 的結果
field_offset數值欄位偏移量。如果未指定欄位偏移量,則會擷取下一個(尚未由此函式擷取的)欄位。field_offset 從 0 開始。
範例 #1 cubrid_fetch_field() 範例
<?php
$conn = cubrid_connect("localhost", 33000, "demodb");
$req = cubrid_execute($conn, "SELECT event_code,athlete_code,nation_code,game_date FROM game WHERE host_year=1988 and event_code=20001;");
var_dump(cubrid_fetch_row($req));
cubrid_field_seek($req, 1);
$field = cubrid_fetch_field($req);
printf("\n--- Field Properties ---\n");
printf("%-30s %s\n", "name:", $field->name);
printf("%-30s %s\n", "table:", $field->table);
printf("%-30s \"%s\"\n", "default value:", $field->def);
printf("%-30s %d\n", "max length:", $field->max_length);
printf("%-30s %d\n", "not null:", $field->not_null);
printf("%-30s %d\n", "primary key:", $field->primary_key);
printf("%-30s %d\n", "unique key:", $field->unique_key);
printf("%-30s %d\n", "multiple key:", $field->multiple_key);
printf("%-30s %d\n", "numeric:", $field->numeric);
printf("%-30s %d\n", "blob:", $field->blob);
printf("%-30s %s\n", "type:", $field->type);
printf("%-30s %d\n", "unsigned:", $field->unsigned);
printf("%-30s %d\n", "zerofill:", $field->zerofill);
cubrid_close_request($req);
cubrid_disconnect($conn);
?>以上範例將輸出
array(4) {
[0]=>
string(5) "20001"
[1]=>
string(5) "16681"
[2]=>
string(3) "KOR"
[3]=>
string(9) "1988-9-30"
}
--- Field Properties ---
name: athlete_code
table: game
default value: ""
max length: 0
not null: 1
primary key: 1
unique key: 1
multiple key: 0
numeric: 1
blob: 0
type: integer
unsigned: 0
zerofill: 0