pg_send_query
(PHP 4 >= 4.2.0)
pg_send_query -- 傳送異步查詢
說明
bool pg_send_query ( resource connection, string query)
bool pg_send_query ( string query)
pg_send_query() 向 connection 連接發送異步查詢。和 pg_query() 不同,它可以向 PostgreSQL 傳送多個查詢並用 pg_get_result() 依次得到結果。當執行查詢時腳本的執行不會被鎖定。用 pg_connection_busy() 來檢查連線連線是否為忙(即查詢正在執行中)。調用 pg_cancel_query() 則有可能取消查詢。
儘管用戶可以一次傳送多個查詢,但用戶不能通過正忙的連線傳送多個查詢。如果向正忙的連線傳送了查詢,則會等待上一條查詢結束並丟棄所有結果。
例子,用於異步查詢
<?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 #3Resource id #3 has 3 records second call to pg_get_result(): Resource id #4 Resource id #4 has 1 records