pg_escape_string

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

pg_escape_string — 쿼리를 위한 이스케이프 문자열


설명

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

pg_escape_string()은 데이터베이스 쿼리를 위해 문자열을 이스케이프합니다. 따옴표 없이 PostgreSQL 형식으로 이스케이프된 문자열을 반환합니다. pg_escape_literal()은 PostgreSQL용 SQL 매개변수를 이스케이프하는 더 선호되는 방법입니다. addlashes()는 PostgreSQL과 함께 사용하면 안 됩니다. 열의 유형이 바이트이면 pg_escape_bytea()를 대신 사용해야 합니다. pg_escape_identifier()는 식별자(예: 테이블 이름, 필드 이름)를 이스케이프하는 데 사용해야 합니다.

메모: 이 함수를 사용하려면 PostgreSQL 7.2 이상이 필요합니다.


매개변수

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

반환 값

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


변경 로그

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

Examples

예제 #1 pg_escape_string() 예제

                  
<?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_string($data);

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

기타

  • pg_escape_bytea() - 바이트 필드에 삽입하기 위해 문자열을 이스케이프 처리합니다.