User's Manual

Extending the Basic Employee Form
5-2 Oracle Database Express Edition 2 Day Plus PHP Developer Guide Beta Draft
else {
construct_employees();
}
...
3. Edit anyco.php. Add the construct_insert_emp() function:
function construct_insert_emp()
{
$conn = db_connect();
$query = "SELECT job_id, job_title
FROM jobs
ORDER BY job_title ASC";
$jobs = db_do_query($conn, $query,
OCI_FETCHSTATEMENT_BY_COLUMN);
$query = "SELECT sysdate FROM dual";
$date = db_do_query($conn, $query,
OCI_FETCHSTATEMENT_BY_COLUMN);
$emp = array(
'DEPARTMENT_ID' => 10, // Default to department 10
'HIRE_DATE' => $date['SYSDATE'][0],
'ALLJOBIDS' => $jobs['JOB_ID'],
'ALLJOBTITLES' => $jobs['JOB_TITLE']
);
ui_print_header('Insert New Employee');
ui_print_insert_employee($emp, $_SERVER['SCRIPT_NAME']);
// Note: The two kinds of date used:
// 1) SYSDATE for storing an SQL date in the database, and
// 2) The PHP date for display in the footer of each page
ui_print_footer(date('Y-m-d H:i:s'));
}
The construct_insert_emp() function executes two queries to obtain default
data to be used to populate the insert employee form, which is displayed by the
ui_print_insert_employee() function.
The $query of the JOBS table obtains a list of all the existing job ID's and their
descriptions in order to build a list for selecting a job type in the HTML form
generated by the ui_print_insert_employee() function.
The $query using SYSDATE obtains the current database date and time for setting
the default hire date of the new employee.
There are two kinds of date used in the application code, the PHP date()
function for printing the date and time in the page footer, and the Oracle SYSDATE
function to obtain the default date and time for displaying in the employee HTML
form's hire date field and to ensure the field text is entered in the correct database
format.
The two db_do_query() function calls provide an additional parameter value
OCI_FETCHSTATEMENT_BY_COLUMNS to specify that the return type for query is
an array of column values.
4. Edit anyco.php. In the construct_employees() function modify the
db_do_query() call to supply OCI_FETCHSTATEMENT_BY_ROW as the last
parameter, and provide $_SERVER['SCRIPT_NAME'] as second parameter in the
ui_print_employees() call: