查詢

fbird_field_info()函式—用法及示例

「 獲取 Firebird 資料庫查詢結果集中欄位的詳細資訊 」


函式名稱:fbird_field_info()

適用版本:Firebird 2.0.0 或更高版本(PHP 5 >= 5.3.0, PHP 7, PHP 8)

用法:fbird_field_info() 函式用於獲取 Firebird 資料庫查詢結果集中欄位的詳細資訊。

語法:array fbird_field_info ( resource $result [, int $field_number = -1 ] )

引數:

  • result: Firebird 查詢結果的資源識別符號。
  • field_number(可選): 欄位的索引或名稱。預設值為 -1,表示返回所有欄位的資訊。

返回值:返回一個關聯陣列,包含欄位資訊的各個屬性。

欄位資訊陣列的鍵包括:

  • name: 欄位名稱。
  • alias: 欄位的別名(如果有)。
  • relation: 欄位所屬的表名。
  • length: 欄位的長度。
  • type: 欄位的資料型別。
  • scale: 欄位的小數位數。
  • precision: 欄位的精度。
  • nullable: 欄位是否可以為空(true 或 false)。
  • charset: 欄位的字符集。
  • collation: 欄位的排序規則。

示例:

<?php
// 假設已經連線到 Firebird 資料庫並執行了查詢
$query = "SELECT * FROM my_table";
$result = fbird_query($connection, $query);

// 獲取第一個欄位的資訊
$fieldInfo = fbird_field_info($result, 0);

// 列印欄位資訊
echo "欄位名稱:" . $fieldInfo['name'] . "\n";
echo "欄位別名:" . $fieldInfo['alias'] . "\n";
echo "欄位所屬表:" . $fieldInfo['relation'] . "\n";
echo "欄位長度:" . $fieldInfo['length'] . "\n";
echo "欄位資料型別:" . $fieldInfo['type'] . "\n";
echo "欄位小數位數:" . $fieldInfo['scale'] . "\n";
echo "欄位精度:" . $fieldInfo['precision'] . "\n";
echo "欄位是否可為空:" . ($fieldInfo['nullable'] ? '是' : '否') . "\n";
echo "欄位字符集:" . $fieldInfo['charset'] . "\n";
echo "欄位排序規則:" . $fieldInfo['collation'] . "\n";
?>

注意事項:

  • 在使用 fbird_field_info() 函式之前,必須先連線到 Firebird 資料庫並執行查詢。
  • 如果指定了 field_number 引數,則只返回指定欄位的資訊;否則,返回所有欄位的資訊。
補充糾錯
上一個函式: fbird_fetch_object()函式
熱門PHP函式
分享連結