pg_escape_literal

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

pg_escape_literal — 텍스트 필드에 삽입하기 위해 리터럴을 이스케이프합니다.


설명

pg_escape_literal(PgSql\Connection $connection = ?, string $data): string

pg_escape_literal()은 PostgreSQL 데이터베이스 쿼리를 위한 리터럴을 이스케이프합니다. PostgreSQL 형식으로 이스케이프된 리터럴을 반환합니다. pg_escape_literal()은 데이터 앞뒤에 따옴표를 추가합니다. 사용자는 따옴표를 추가해서는 안 됩니다. pg_escape_string() 대신 이 함수를 사용하는 것이 좋습니다. 열의 유형이 바이트이면 pg_escape_bytea()를 대신 사용해야 합니다. 이스케이프 식별자(예: 테이블, 필드 이름)의 경우 pg_escape_identifier()를 사용해야 합니다.

메모: 이 함수에는 내부 이스케이프 코드가 있으며 PostgreSQL 8.4 이하에서도 사용할 수 있습니다.


매개변수

connection
PgSql\Connection 인스턴스. connection을 지정하지 않으면 기본 연결이 사용됩니다. 기본 연결은 pg_connect() 또는 pg_pconnect()에 의해 만들어진 마지막 연결입니다.
data
이스케이프할 텍스트가 포함된 문자열입니다.

반환 값

이스케이프된 데이터가 포함된 문자열입니다.


변경 로그

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

Examples

예제 #1 pg_escape_literal() 예제

                  
<?php
  // Connect to the database
  $dbconn = pg_connect('dbname=foo');

  // Read in a text file (containing apostrophes and backslashes)
  $data = file_get_contents('letter.txt');

  // Escape the text data
  $escaped = pg_escape_literal($data);

  // Insert it into the database. Note that no quotes around {$escaped}
  pg_query("INSERT INTO correspondence (name, data) VALUES ('My letter', {$escaped})");
?>
                  
                

기타