array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.pg-get-result.php', 1 => 'pg_get_result', ), 'up' => array ( 0 => 'ref.pgsql.php', 1 => 'PostgreSQL 関数', ), 'prev' => array ( 0 => 'function.pg-get-pid.php', 1 => 'pg_get_pid', ), 'next' => array ( 0 => 'function.pg-host.php', 1 => 'pg_host', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/pgsql/functions/pg-get-result.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
pg_get_result — 非同期クエリの結果を取得する
pg_get_result() は、 pg_send_query(), pg_send_query_params() あるいは pg_send_execute() で実行した非同期クエリから PgSql\Result クラスのインスタンスを取得します。
pg_send_query() およびその他の非同期クエリ関数は、 複数のクエリを PostgreSQL サーバーに送信することが可能です。クエリの結果を ひとつずつ取得するには、pg_get_result() を使用します。
PgSql\Result クラスのインスタンスを返します。
結果がもうない場合に false
を返します。
バージョン | 説明 |
---|---|
8.1.0 | PgSql\Result クラスのインスタンスを返すようになりました。 これより前のバージョンでは、リソース を返していました。 |
8.1.0 |
connection は、PgSql\Connection クラスのインスタンスを期待するようになりました。
これより前のバージョンでは、リソース を期待していました。
|
例1 pg_get_result() の例
<?php
$dbconn = pg_connect("dbname=publisher") or die("Could not connect");
if (!pg_connection_busy($dbconn)) {
pg_send_query($dbconn, "select * from authors; select count(*) from authors;");
}
$res1 = pg_get_result($dbconn);
echo "First call to pg_get_result(): $res1\n";
$rows1 = pg_num_rows($res1);
echo "$res1 has $rows1 records\n\n";
$res2 = pg_get_result($dbconn);
echo "Second call to pg_get_result(): $res2\n";
$rows2 = pg_num_rows($res2);
echo "$res2 has $rows2 records\n";
?>
上の例の出力は以下となります。
First call to pg_get_result(): Resource id #3 Resource id #3 has 3 records Second call to pg_get_result(): Resource id #4 Resource id #4 has 1 records