PreviousNext
Help > API Functions > SQL Queries & Procedures > i5_execute
i5_execute

 

Executes SQL prepared request (stored procedure).

 

Syntax n°1

 

        bool i5_ execute (resource Stmt [, mixed/array param])

 

Syntax n°2

There is the possibility to pass SQL request parameters:

        bool i5_ execute (resource Stmt [, mixed param1, param2, param3…])

 

 

Parameters

 

stmt

i5_prepare returned request ID

param

Array containing input parameters values, matching with marker

param1, param2, param3…

Input parameters values matching with marker

 

Return

Returns a Boolean and update stmt resource in case of success FALSE if it fails.

 

I5_ERR_PHP_HDLBAD

258

Bad connection handle

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_BINDPARAM

276

Internal error; please contact Aura Equipements. error number 276

 

 Details

 

i5_execute executes an SQL request prepared with i5_prepare.

If the SQL request returns a result set, i.e., a SELECT, a line can be collected (as a table or object) from the query resource with i5_fetch_xxx.

If the request creates results sets (CALL statement), i5_next_result function moves pointer to the next available set. If option I5_OPTIONS_AUTOMATIC_NEXT_RESULT wasn’t set to "1" during connection, you need to call i5_next_result() to get the first result set.

 

i5_execute is much more efficient than i5_query if the same request must be run several times with only few parameter changes. See i5_prepare for a short statement on using i5_prepare and i5_execute advantages versus i5_query.

 

Parameters of prepared request or stored procedure may be set using i5_setparam function and collected using i5_getparam function (for IN/OUT or OUT parameters).

 

 

Example

 

 

 

    $nom = 'C-04';

    //Prepared request creation

    $req = i5_prepare('SELECT FIRSTNAME, LASTNAME FROM EASYCOMXMP/SP_CUST WHERE CUST_ID=:custid');

   

    if ($req)

    {

   

                   /* Set input parameter value */
                   $ret = i5_setparam($req, "custid", $nom);

                  

                   if (!$ret)

                   {

                                   print_r("i5_setparam error : ".i5_errormsg().'<br/>');

                   }

 

                   /* Request execution */

                   $ret = i5_execute($req);

                   if (!$ret)

                   {

                                   print_r("i5_execute error : ".i5_errormsg().'<br/>');

                   }

 

                   /* Values reading */

                   $ret = i5_fetch_row($req);

                   if (is_bool($ret))

                   {

                                   if (i5_errno () == I5_ERR_BEOF) {

                                                   echo "No data, cursor before or end of file<BR>";

                                   }

                                   else{

                                                   print_r("i5_fetch_row error : ".i5_errormsg().'<br/>');

                                   }

                   }

                   else

                   {

                                   printf('Firstname : %s - Lastname %s<BR>', $ret[0], $ret[1]);

                   }

   

                   /* Request execution with new parameter value, using array */
                   $newRecord = array('C-03');

                   $ret = i5_execute($req,$newRecord);

                   if (!$ret)

                   {

                                   print_r("i5_execute error : ".i5_errormsg().'<br/>');

                   }

                   else

                   {

                                   /* Values reading */

                                   $ret = i5_fetch_row($req);

                                   if (is_bool($ret))

                                   {

                                                   if (i5_errno () == I5_ERR_BEOF) {

                                                                   echo "No data, cursor before or end of file<BR>";

                                                   }

                                                   else{

                                                                   print_r("i5_fetch_row error : ".i5_errormsg().'<br/>');

                                                   }

                                   }

                                   else

                                   {

                                                   printf('Firstname : %s - Lastname %s<BR>', $ret[0], $ret[1]);

                                   }

 

                   }

 

                   /* Request execution with new parameter value, using parameter value */

                   $newRec = "C-05";

                   $ret = i5_execute($req,$newRec);

                   if (!$ret)

                   {

                                   print_r("i5_execute error : ".i5_errormsg().'<br/>');

                   }

                   else

                   {

                                   /* Values reading */

                                   $ret = i5_fetch_row($req);

                                   if (is_bool($ret))

                                   {

                                                   if (i5_errno () == I5_ERR_BEOF) {

                                                                   echo "No data, cursor before or end of file<BR>";

                                                   }

                                                   else{

                                                                   print_r("i5_fetch_row error : ".i5_errormsg().'<br/>');

                                                   }

                                   }

                                   else

                                   {

                                                   printf('Firstname : %s - Lastname %s<BR>', $ret[0], $ret[1]);

                                   }

                   }

 

                   /* Command closing */

                   $ret = i5_free_query($req);

                   if (!$ret)

                   {

                                   print_r("i5_free_query error : ".i5_errormsg().'<br/>');

                   }

    }

    else

    {

                   print_r("i5_prepare error : ".i5_errormsg().'<br/>');

    } 

 

See also

 

i5_prepare