Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: pg_fetch_result - Manual
[go: Go Back, main page]

PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<pg_fetch_objectpg_fetch_row" width="11" height="7"/>
view the version of this page
Last updated: Sun, 07 May 2006

pg_fetch_result

(PHP 4 >= 4.2.0, PHP 5)

pg_fetch_result -- 結果リソースから値を返す

説明

string pg_fetch_result ( resource result, int row, mixed field )

string pg_fetch_result ( resource result, mixed field )

pg_fetch_result() は、PostgreSQL 結果リソースから 特定の行とフィールド(カラム)の値を返します。

パラメータ

result

pg_query(), pg_query_params() あるいは pg_execute() から返される PostgreSQL の クエリ結果リソース。

row

結果から取得する行の番号。行番号は 0 から始まります。指定しなかった 場合は、次の行が読み込まれます。

field

取得するフィールド(カラム)の名前を表す文字列、あるいは取得する フィールドの番号。フィールド番号は 0 から始まります。

返り値

論理型の値は "t" あるいは "f" の形式で返します。 配列を含むそれ以外の型は、PostgreSQL のやりかたにしたがって文字列として フォーマットされた形式で返します。これは psql プログラムの出力と同じ形式です。データベースの NULL 値は、NULL として返します。

row が結果の行数より大きい場合、 あるいはそれ以外のエラーが発生した場合は FALSE を返します。

例 1. pg_fetch_result() の例

<?php
$db
= pg_connect("dbname=users user=me") || die();

$res = pg_query($db, "SELECT 1 UNION ALL SELECT 2");

$val = pg_fetch_result($res, 1, 0);

echo
"First field in the second row is: ", $val, "\n";
?>

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

First field in the second row is: 2



add a note add a note User Contributed Notes
pg_fetch_result
Akbar
02-Dec-2004 01:01
Use can use pg_fetch_result when getting a value (like a smallint as in this example) returned by your stored procedure

<?php
$pgConnection
= pg_connect("dbname=users user=me");

$userNameToCheckFor = "metal";

$result = pg_query($pgConnection, "SELECT howManyUsersHaveThisName('$userNameToCheckFor')");

$count = pg_fetch_result($result, 0, 'howManyUsersHaveThisName');

?>
newby_AT_nobletec_DOT_com
05-Sep-2002 12:12
Comment on boolean fields:

If you retrieve a boolean value from the PostgreSQL database, be aware that the value returned will be either the character 't' or the character 'f', not an integer.  So, the statement

     if (pg_fetch_result($rsRecords,0,'blnTrueFalseField')) {
       echo "TRUE";
     } else {
       echo "FALSE";
     }

will echo "TRUE" in either case (True or False stored in the field).  In order to work as expected, do this instead:

     if (pg_fetch_result($rsRecords,0,'blnTrueFalseField') == 't') {
       echo "TRUE";
     } else {
       echo "FALSE";
     }

<pg_fetch_objectpg_fetch_row" width="11" height="7"/>
 Last updated: Sun, 07 May 2006
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2006 The PHP Group
All rights reserved.
This mirror generously provided by: PacketBusiness, Inc.
Last updated: Wed Jun 28 13:19:26 2006 JST