pg_send_execute
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
pg_send_execute — 결과를 기다리지 않고 주어진 매개변수로 준비된 명령문을 실행하라는 요청을 보냅니다.
설명
pg_send_execute(PgSql\Connection $connection
, string $statement_name
, array $params
): int|bool
결과를 기다리지 않고 주어진 매개변수로 준비된 명령문을 실행하라는 요청을 보냅니다.
이는 pg_send_query_params()와 유사하지만 쿼리 문자열을 제공하는 대신 이전에 준비된 명령문의 이름을 지정하여 실행할 명령을 지정합니다. 함수의 매개변수는 pg_execute()와 동일하게 처리됩니다. pg_execute()와 마찬가지로 PostgreSQL 7.4 이전 버전에서는 작동하지 않습니다.
매개변수
connection
- PgSql\Connection 인스턴스.
statement_name
- 실행할 준비된 문의 이름입니다. ""가 지정되면 이름 없는 명령문이 실행됩니다. 이름은 pg_prepare(), pg_send_prepare() 또는
PREPARE
SQL 명령을 사용하여 미리 준비되어 있어야 합니다. params
- 원래 준비된 쿼리 문자열에서 $1, $2 등의 자리 표시자를 대체할 매개변수 값의 배열입니다. 배열의 요소 수는 자리 표시자의 수와 일치해야 합니다.
반환 값
성공하면 true
, 실패하면 false
또는 0
을 반환합니다. 쿼리 결과를 확인하려면 pg_get_result()를 사용하십시오.
변경 로그
버전 | 설명 |
---|---|
8.1.0 | connection 매개변수는 이제 PgSql\Connection 인스턴스를 필요로 합니다. 이전에는 resource가 필요했습니다. |
Examples
예제 #1 pg_send_execute() 사용
<?php
$dbconn = pg_connect("dbname=publisher") or die("Could not connect");
// Prepare a query for execution
if (!pg_connection_busy($dbconn)) {
pg_send_prepare($dbconn, "my_query", 'SELECT * FROM shops WHERE name = $1');
$res1 = pg_get_result($dbconn);
}
// Execute the prepared query. Note that it is not necessary to escape
// the string "Joe's Widgets" in any way
if (!pg_connection_busy($dbconn)) {
pg_send_execute($dbconn, "my_query", array("Joe's Widgets"));
$res2 = pg_get_result($dbconn);
}
// Execute the same prepared query, this time with a different parameter
if (!pg_connection_busy($dbconn)) {
pg_send_execute($dbconn, "my_query", array("Clothes Clothes Clothes"));
$res3 = pg_get_result($dbconn);
}
?>
기타
- pg_prepare() - 주어진 매개변수로 준비된 명령문 생성 요청을 제출하고 완료될 때까지 기다립니다.
- pg_send_prepare() - 완료를 기다리지 않고 주어진 매개변수로 준비된 명령문을 생성하라는 요청을 보냅니다.
- pg_execute() - 주어진 매개변수로 준비된 명령문을 실행하라는 요청을 보내고 결과를 기다립니다.