User's Manual
Writing Queries with Bind Variables
4-4 Oracle Database Express Edition 2 Day Plus PHP Developer Guide Beta Draft
}
}
Remember the END; line must not be prefixed with leading spaces otherwise the
rest of the document is treated as part of the text to be printed.
5. Edit anyco.php. Include anyco_ui.inc and anyco_db.inc, and call the
database functions to query and display information for a department with a
department_id of 80 by using the following code. The file becomes:
<?php // File: anyco.php
require('anyco_cn.inc');
require('anyco_db.inc');
require('anyco_ui.inc');
$query =
'SELECT department_id, department_name, manager_id, location_id
FROM departments
WHERE department_id = 80';
$conn = db_connect();
$dept = db_do_query($conn, $query);
ui_print_header('Departments');
ui_print_department($dept[0]);
ui_print_footer(date('Y-m-d H:i:s'));
?>
6. To test the resulting changes to the application, in a browser window enter the
following URL:
http://localhost/~<username>/chap4/anyco.php
The page returned in the browser window should resemble the following page:
Writing Queries with Bind Variables
Using queries with hard coded values in the WHERE clause may be useful for some
situations. However, if the query conditional values need to change it is not
appropriate to encode a value into the query. Oracle recommends you use bind
variables in the query as a placeholder replacing literal values in the query conditions.
A bind variable is a symbolic name preceded by a colon in the query that acts as a
placeholder for literal values in the WHERE clause. For example, the query string
created in the anyco.php file could be rewritten with the bind variable ":did":
$query =
'SELECT department_id, department_name, manager_id, location_id