PHP.nl

pg_escape_string

pg_escape_string

Escape a string for query

string **pg_escape_string** PgSql\Connection $connection string $data
escapes a string for querying

the database. It returns an escaped string in the PostgreSQL format without quotes. is more preferred way to escape SQL parameters for PostgreSQL. must not be used with PostgreSQL. If the type of the column is bytea, must be used instead. must be used to escape identifiers (e.g. table names, field names) pg_escape_string``pg_escape_literal``addslashes``pg_escape_bytea``pg_escape_identifier

connection``data A containing text to be escaped. string

A containing the escaped data. string

Voorbeeld: 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_string($data);
  
  // Insert it into the database
  pg_query("INSERT INTO correspondence (name, data) VALUES ('My letter', '{$escaped}')");
?>

pg_escape_bytea