Tell Me
 

Creating a Generic Query Function

Previous previous|next Next Page

The hr_db.inc file contains a db_do_query() function that performs the following steps (with OCI8 library calls shown) to execute a query, optionally with bind variables:

Assign PHP variable values to query bind variables with oci_bind_by_name().
Execute the query with oci_execute().
Fetch the result set with oci_fetch_all(). Take care using this OCI function with large result sets.

The db_do_query() function provides the following parameters:

$statement containing the query string
$resulttype specifying how the result set is return, either as an array of rows each containing an array of columns (the default OCI_FETCHSTATEMENT_BY_ROW), or as an array of columns each containing an array of the row values in that column (OCI_FETCHSTATEMENT_BY_COLUMN)

$bindvars: an optional array containing one or more bind variable arrays. Each bind variable array may contain the name of the bind variable in the query, the value to be associated with the bind variable, and a length of the value.

For IN bind variables, which provide input values to a query, the length can be set to -1. In this case, the OCI8 layer dynamically determines the length of the value. For OUT bind variables, for values returned by a query, the length must be set to a suitable value for the expected result.

The db_do_query() function returns the result set as an array or rows or columns, depending on the value of the $resulttype parameter. The function returns a false value if an error occurs.