User's Manual

Centralizing the Database Application Logic
Beta Draft Querying Data 4-3
Q The null in the fourth parameter for the maximum number of rows to fetch is
ignored. In this case, all the rows for the query are returned. For this example
where the result set is not large, it is acceptable.
Q The last parameter flag OCI_FETCHSTATEMENT_BY_ROW indicates that the
data in the $results array is organized by row, where each row contains an
array of column values. A value of OCI_FETCHSTATEMENT_BY_COLUMN
causes the results array to be organized by column, where each column
entry contains an array of column values for each row. Your choice of value for
this flag depends on how you intend to process the data in your logic.
To examine the structure of the result array use the PHP var_dump() function
after the query has been executed. This is useful for debugging. For example:
print '<pre>';
var_dump($results);
print '</pre>';
The db_error() function, accepts three arguments. The $r parameter can be
false or null for obtaining connection errors, or a connection resource or statement
resource to obtain an error for those contexts. The $file and $line values are
populated by using __FILE__ and __LINE__ respectively as the actual
parameters to enable the error message to display the source file and line from
which the database error is reported. This enables you to easily track the possible
cause of errors.
The db_ error() function calls the oci_error() function to obtain database
error messages.
The db_error() function calls isset() function checks if the message
component of the database error structure is set before printing the message, or
indicating that the error is unknown.
4. Edit anyco_ui.inc. To format the results of single row from the
DEPARTMENTS table query in a HTML table format, insert the following
function:
function ui_print_department($dept)
{
if (!$dept) {
echo '<p>No Department found</p>';
}
else {
echo <<<END
<table>
<tr>
<th>Department<br>ID</th>
<th>Department<br>Name</th>
<th>Manager<br>Id</th>
<th>Location ID</th>
</tr>
<tr>
END;
echo '<td>'.htmlentities($dept['DEPARTMENT_ID']).'</td>';
echo '<td>'.htmlentities($dept['DEPARTMENT_NAME']).'</td>';
echo '<td>'.htmlentities($dept['MANAGER_ID']).'</td>';
echo '<td>'.htmlentities($dept['LOCATION_ID']).'</td>';
echo <<<END
</tr>
</table>
END;