Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online

pg prepare function syntax tag tutorial 2013





Alert! Connect with 10,000 Chating Online. Join Now

Php pg prepare () function

Write your php code

 
<?php ?>

Php Result


Your code below



(no version information, might be only in CVS)

pg_prepare -- Prepares a query for future execution

Syntax

resource pg_prepare ( string stmtname, string query )

resource pg_prepare ( resource connection, string stmtname, string query )

pg_prepare() returns a query result resource if query could be prepared. 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_prepare() prepares an SQL statement for the PostgreSQL database connection specified by the connection resource. 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. The stmtname is the name of the prepared query, for future use with pg_execute() or pg_send_execute().

Note: connection is an optional parameter for pg_prepare(). 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.

Parameters to pg_prepare() are specified using placeholders in the query. It is not necessary to quote parameters as quoting and escaping is done automatically. Placeholders are indicated in the query by $1, $2, $3 and so on.

Using prepared queries means you can prepare one and then execute many times, with different parameters. PostgreSQL will cache the query plan on the prepare, then re-use it for each execute, resulting in speed improvements. There is no need to use a prepared query if it will only be executed once. In this case, it is simpler to use pg_query_params().

Examples

Example 1. Using pg_prepare()

<?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"));

?>

Php pg prepare Function syntax tag

pg prepare php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online



Php pg prepare syntax tutorial

php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.


Function index

Variables

Expressions

Operators

Control-Structures

Cookies

Array

Date & Time

Directory function

File

Image

Operators

Form data handling

Mathematics operators

Mail

Php Mysql

Network Functions

Strings

php tutorial guides,functions, classes, code examples and tags for creating simple dynamic site to mysql database driven sites
 
 
Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online