Manuel PHP
Précédent |  | Suivant

# pg_execute

(no version information, might be only in CVS)

pg_execute -- Execute a previously prepared query

## Description

resource pg_execute ( string stmtname, array params )
resource pg_execute ( resource connection, string stmtname, array params )

pg_execute() returns a query result resource if the named prepared query could be executed with the given parameters. It returns `FALSE` on failure or if connection is not a valid connection. Details about the error can be retrieved using the pg_last_error() function if connection is valid. pg_execute() executes a previously prepared query on the connection resource with the specified parameters. It is identical to pg_query_params() except that it takes the name of a previously prepared query instead of an actual query. The connection must be a valid connection that was returned by pg_connect() or pg_pconnect(). The return value of this function is an query result resource to be used to access the results from other PostgreSQL functions such as pg_fetch_array().

> Note : connection is an optional parameter for pg_execute(). If connection is not set, default connection is used. Default connection is the last connection made by pg_connect() or pg_pconnect().

> Although connection can be omitted, it is not recommended, since it could be a cause of hard to find bug in script.

## Exemples

Exemple 1. Using pg_execute()

`<?php
// Connect to a database named "mary"
$dbconn = pg_connect("dbname=mary");
// Prepare a query for execution
$result = pg_prepare($dbconn, "my_query", 'SELECT * FROM shops WHERE name = $1');
// Execute the prepared query. Note that it is not necessary to escape
// the string "Joe's Widgets" in any way
$result = pg_execute($dbconn, "my_query", array("Joe's Widgets"));
// Execute the same prepared query, this time with a different parameter
$result = pg_execute($dbconn, "my_query", array("Clothes Clothes Clothes"));
?>`

## Voir aussi

pg_connect()
pg_pconnect()
pg_prepare()
pg_send_execute()

Précédent | Sommaire | Suivant
pg_escape_string | Niveau supérieur | pg_fetch_all