pg_send_prepare

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

pg_send_prepare — 완료를 기다리지 않고 주어진 매개변수로 준비된 명령문을 생성하라는 요청을 보냅니다.


설명

pg_send_prepare(PgSql\Connection $connection, string $statement_name, string $query): int|bool

완료를 기다리지 않고 주어진 매개변수를 사용하여 준비된 명령문을 생성하라는 요청을 보냅니다.

이것은 pg_prepare()의 비동기 버전입니다. 요청을 전달할 수 있으면 true를 반환하고 그렇지 않으면 false를 반환합니다. 호출이 성공하면 pg_get_result()를 호출하여 서버가 준비된 명령문을 성공적으로 생성했는지 확인합니다. 함수의 매개변수는 pg_prepare()와 동일하게 처리됩니다. pg_prepare()와 마찬가지로 PostgreSQL 7.4 이전 버전에서는 작동하지 않습니다.


매개변수

connection
PgSql\Connection 인스턴스.
statement_name
준비된 명령문을 제공할 이름입니다. 연결별로 고유해야 합니다. ""가 지정되면 이름 없는 명령문이 생성되어 이전에 정의된 이름 없는 명령문을 덮어씁니다.
query
매개변수화된 SQL 문. 하나의 문만 포함해야 합니다. (세미콜론으로 구분된 여러 문장은 허용되지 않습니다.) 매개변수를 사용하는 경우 $1, $2 등으로 지칭합니다.

반환 값

성공하면 true, 실패하면 false 또는 0을 반환합니다. 쿼리 결과를 확인하려면 pg_get_result()를 사용하십시오.


변경 로그

버전 설명
8.1.0 connection 매개변수는 이제 PgSql\Connection 인스턴스를 필요로 합니다. 이전에는 resource가 필요했습니다.

Examples

예제 #1 pg_send_prepare() 사용

                  
<?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_connect() - PostgreSQL 연결 열기
  • pg_pconnect() - 영구 PostgreSQL 연결 열기
  • pg_execute() - 주어진 매개변수로 준비된 명령문을 실행하라는 요청을 보내고 결과를 기다립니다.
  • pg_send_execute() - 결과를 기다리지 않고 주어진 매개변수로 준비된 명령문을 실행하라는 요청을 보냅니다.
  • pg_send_query_params() - 결과를 기다리지 않고 명령과 별도의 매개변수를 서버에 제출