pg_send_prepare
(PHP 5 >= 5.1.0, PHP 7)
pg_send_prepare — Sends a request to create a prepared statement with the given parameters, without waiting for completion
Description
$connection
, string $stmtname
, string $query
) : boolSends a request to create a prepared statement with the given parameters, without waiting for completion.
This is an asynchronous version of pg_prepare(): it returns TRUE
if it was able to
dispatch the request, and FALSE
if not. After a successful call, call
pg_get_result() to determine whether the server successfully created the
prepared statement. The function's parameters are handled identically to
pg_prepare(). Like pg_prepare(), it will not work
on pre-7.4 versions of PostgreSQL.
Parameters
-
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(). -
stmtname
-
The name to give the prepared statement. Must be unique per-connection. If "" is specified, then an unnamed statement is created, overwriting any previously defined unnamed statement.
-
query
-
The parameterized SQL statement. Must contain only a single statement. (multiple statements separated by semi-colons are not allowed.) If any parameters are used, they are referred to as $1, $2, etc.
Return Values
Returns TRUE
on success, FALSE
on failure. Use pg_get_result()
to determine the query result.
Examples
Example #1 Using pg_send_prepare()
<?php
$dbconn = pg_connect("dbname=publisher") or die("Could not connect");
// Prepare a query for execution
if (!pg_connection_busy($dbconn)) {
pg_send_prepare($dbconn, "my_query", 'SELECT * FROM shops WHERE name = $1');
$res1 = pg_get_result($dbconn);
}
// Execute the prepared query. Note that it is not necessary to escape
// the string "Joe's Widgets" in any way
if (!pg_connection_busy($dbconn)) {
pg_send_execute($dbconn, "my_query", array("Joe's Widgets"));
$res2 = pg_get_result($dbconn);
}
// Execute the same prepared query, this time with a different parameter
if (!pg_connection_busy($dbconn)) {
pg_send_execute($dbconn, "my_query", array("Clothes Clothes Clothes"));
$res3 = pg_get_result($dbconn);
}
?>
See Also
- pg_connect() - Open a PostgreSQL connection
- pg_pconnect() - Open a persistent PostgreSQL connection
- pg_execute() - Sends a request to execute a prepared statement with given parameters, and waits for the result
- pg_send_execute() - Sends a request to execute a prepared statement with given parameters, without waiting for the result(s)
- pg_send_query_params() - Submits a command and separate parameters to the server without waiting for the result(s)
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-pg-send-prepare.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.