602SQL Documentation Index  



resource wb_exec( resource connection, string SQL_statement )


Identifier of the open connection returned by the wb_connect or wb_pconnect function.
SQL statement or query that is to be executed. The SQL statement may contain client variables prefixed with a colon. The specified statement or query may be composed from more statements or queries separated by a semicolon.


The function executes a SQL statement or opens a query specified as the second parameter. The SQL statement (or the query) can be also executed by calling the wb_psql_prepare and wb_psql_execute functions (see prepared SQL functions for more information).

If the SQL statement contains client variables (host variables), the value of the PHP variable is inserted instead of the actual parameter (see example). The variable must be of a corresponding type: database types BOOLEAN, REAL and INTEGER correspond with the boolean, float and long types in PHP; string variable is used for CLOB, and if it is an OUT parameter, the size will be enlarged up to the needed size (wb_longreadlen parameter value).

The passing of text PHP variables is affected by the current coding of the PHP text variables (this coding is set by the wb_set_client_encoding function). If the WB_ENC_UTF8 coding is set, the values of the string PHP variables will be converted from UTF-8 to UCS-2 and this value will be passed to the SQL Server.

It is possible to pass the TIME, TIMESTAMP or DATE type values to client variables, only if the configuration parameter wb_datestring is wb_datestring=="1". Host variables of the string type that contain a syntactically correct (according to the SQL standard in 602SQL) constant of the DATE, TIME or TIMESTAMP type, will be converted to the corresponding date/time type (e.g. the 602SQL Server will receive these host variables converted into the date/time type when executing the wb_exec() function). Other host variables of the string type will remain unchanged. If wb_datestring=="0", these conversions will not be made.

The configuration parameter wb_datestring is set by the standard PHP function ini_set() (see PHP documentation). This value can also be specified in the PHP.INI file. If the value of this parameter is not set, the default value of 0 will be used.

If the function result is a cursor identifier, this cursor will be closed if no pointer in the PHP program exists to that cursor, or when the wb_close function with the cursor identifier as a parameter is called explicitly. It will also close or automatically at the end of the PHP script.


Returns FALSE on error (you can get the error from the wb_err_str function).

On success:

If the SQL statement contained more statements (separated by semicolons) and all statements were succesful, the return value is the result of the first statement.



Using client variables:

 $res=wb_exec($conn,"SET :>temp = Who_am_I");
 if ($res) 
   {     echo("Prihlasen jako: ".$temp) ;   }		


Use the TIMESTAMP type client variable:

  // prepare local variables
  $string="timestamp ";
  $ts_val="12.5.2002 12:11:10"; // string with the TIMESTAMP constant written according to the SQL rules in 602SQL
  $sql="INSERT INTO Test(id,word,ts_value) VALUES(:<number,:<string,:<ts_val)";
  // set the configuration parameter to 1
  // execute the SQL statement
  // we can set the wb_datestring to the standard value, to prevent the conversion in other SQL statements