PHP 8.3.4 Released!

pg_field_num

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

pg_field_num指定されたフィールドのフィールド番号を返す

説明

pg_field_num(PgSql\Result $result, string $field): int

pg_field_num() は、 指定した結果 (result) インスタンスにおいて field に相当するカラム(フィールド) のフィールド番号を返します。

注意:

この関数は、以前は pg_fieldnum() と呼ばれていました。

パラメータ

result

pg_query()pg_query_params() や (様々な関数がありますが、特に) pg_execute() が返した PgSql\Result クラスのインスタンス。

field

フィールドの名前。 ここで指定された名前は、SQL コマンド内の識別子として扱われます。 つまり、ダブルクォートで囲まれない限り小文字に変換されます。

戻り値

フィールド番号(0 から始まります)を返します。エラー時には -1 を返します。

変更履歴

バージョン 説明
8.1.0 result は、PgSql\Result クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、リソース を期待していました。

例1 フィールドの情報を取得する

<?php
$dbconn
= pg_connect("dbname=publisher") or die("Could not connect");

$res = pg_query($dbconn, "select author, year, title from authors where author = 'Orwell'");

echo
"Column 'title' is field number: ", pg_field_num($res, 'title');
?>

上の例の出力は以下となります。

Column 'title' is field number: 2

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top