i5_prepare

 

Prepares SQLrequest

 

resource i5_prepare (

resource query
[, resource connection] )

 

Details

 

Query parameter may include one or several SQL variables if question marks (?) are set at the right places.

There are three main advantages using prepared requests in your script:

Performance: While preparing a request, database server creates a return optimized path in order to collect the requested data's. Later on, when the i5_prepare prepared request is sent, it will use the path avoiding processor overload with each request sent.

Safety: While preparing a request, it is possible to set markers for entry values. Processing the prepared request with entry values, Easycom checks each entry value to make sure that their type match with the column or the description parameters.

Advanced Functionality: Markers not only allow introducing entry values in stored procedure, but also allow collecting OUTPUT and INPUT/OUTPUT recording procedure parameters using i5_bind_param function.

 

Warning, connections and resources are transient and disappear with each script end, then, the above notes are only in force with set of process appearing in the same script.

 

Parameters

 

query

SQL request to prepare

connection

Connection ID (optional)

 

Returns:

Returns prepared request ID in case of success, FALSE in other case.

 

I5_ERR_PHP_HDLDFT

256

No default connection found.

I5_ERR_PHP_HDLCONN

257

This resource has no connection active.

I5_ERR_PHP_RESOURCE_BAD

261

No resource found .

I5_ERR_PHP_TYPEPARAM

262

Type of element x in parameter -1 must be y. Type z was provided.

I5_ERR_PHP_NBPARAM_BAD

263

Wrong parameter count

 

Example

 

 

$nom = 'DUPOND';

/* Prepared request creation */

$req = i5_prepare('SELECT CVILLE, CCODE, CNOM, CPREN FROM EASYCOM/NCLIENT WHERE CNOM=?');

if ($req) {

/* SQL variables association */ 

$ret = i5_bind_param($req, &$nom);

if (!$ret) trigger_error('i5_bind_param error : '.i5_errormsg(), E_USER_ERROR);

 

/* Request execution */

$ret = i5_execute($req);

if (!$ret) trigger_error('i5_execute error : '.i5_errormsg(), E_USER_ERROR);

 

/* Results variables association */

$ret = i5_bind_result($req, &$ville, &$code, &$nom, &$prenom);

if (!$ret) trigger_error('i5_bind_result error : '.i5_errormsg(), E_USER_ERROR);

 

/* Values reading */

$ret = i5_fetch_row($req);

if (is_bool($ret)) trigger_error('i5_fetch_row error : '.i5_errormsg(), E_USER_ERROR);

printf('%s is in city %s<BR>', $nom, $ville);

 

/* Command closing */

$ret = i5_free_query($req);

if (!$ret) trigger_error('i5_fetch_row error : '.i5_errormsg(), E_USER_ERROR);

} else {

 trigger_error('i5_prepare error : '.i5_errormsg(), E_USER_ERROR);

}

 

See also

 

i5_execute

i5_bind_param

i5_setparam

i5_set_property