PG_ESCAPE_LITERAL(3) PG_ESCAPE_LITERAL(3)
pg_escape_literal - Escape a literal for insertion into a text field
SYNOPSIS
string pg_escape_literal ([resource $connection], string $data)
DESCRIPTION
pg_escape_literal(3) escapes a literal for querying the PostgreSQL database. It returns an escaped literal in the PostgreSQL format.
pg_escape_literal(3) adds quotes before and after data. Users should not add quotes. Use of this function is recommended instead of
pg_escape_string(3). If the type of the column is bytea, pg_escape_bytea(3) must be used instead. For escaping identifiers (e.g. table,
field names), pg_escape_identifier(3) must be used.
Note
This function has internal escape code and can also be used with PostgreSQL 8.4 or less.
PARAMETERS
o $connection
- PostgreSQL database connection resource. When $connection is not present, the default connection is used. The default connection
is the last connection made by pg_connect(3) or pg_pconnect(3).
o $data
- A string containing text to be escaped.
RETURN VALUES
A string containing the escaped data.
EXAMPLES
Example #1
pg_escape_literal(3) example
<?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})");
?>
SEE ALSO
pg_escape_identifier(3), pg_escape_bytea(3), pg_escape_string(3).
PHP Documentation Group PG_ESCAPE_LITERAL(3)