Home > PHP > Function > PostgreSQL > pg_query()

pg_query()

pg_query - Execute a query

Syntax

resource pg_query (resource $connection, string $query)

Arguments

  • 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() or pg_pconnect().
  • query - The SQL statement or statements to be executed. When multiple statements are passed to the function, they are automatically executed as one transaction, unless there are explicit BEGIN/COMMIT commands included in the query string. However, using multiple transactions in one function call is not recommended. Data inside the query should be properly escaped.

Description

pg_query() executes the query on the specified database connection.

Version

PHP 4.2.0, 5

Return value

A query result resource on success or FALSE on failure.