PHP Function Pg_Query
The php function pg_query sends an SQL statement to a PostgreSQL installation and receives the data as an associative array. For inserts or updates to work, the database handle and table name must be supplied in addition to the query. The query must also be escaped (to remove the possibility of dangerous characters such as single quotes).
A SELECT SQL query is sent to the PostgreSQL host via the pg_query() function. The input is an associative array with field names as the keys and values. If the query is an UPDATE or INSERT SQL statement, the update condition must also be submitted as an array in a fourth parameter of the pg_query() function.
The query string must be escaped using the pg_escape_string() function to avoid dangerous character escapes and other issues. The function will also use htmlentities to ensure that all strings are correctly encoded and understood on the PostgreSQL side of things.
When pg_query() is called, it returns an instance of the PgSql
pg_query() can be called with a connection resource as the first parameter or an empty string to use the default database connection. If the connect_type is not PGSQL_CONNECT_FORCE_NEW, a connection must be made by calling pg_connect() or pg_pconnect(). The connection_string can contain various optional parameters including the dbname, pgsql_version, server_encoding, client_encoding, is_superuser, connect_timeout, options, tty, requiressl, and service.