Building the client
Now, you have targeted ORDERS and Order_items
Table creates a registration, we'll look at how the client application that accesses the orders stored in these tables and their order items uses change notifications. To do this, you can build a
PHP
Application, it caches the results of the query against the tables above and takes actions to respond to notifications about changes made to these tables (from
DatabaseThese notifications are received from the server). An easy way is to use
Pear::cache_lite package, which provides you with a reliable mechanism to keep your cached data up-to-date. In particular, you can use the Cache_lite_function
Class (part of the Pear::cache_lite package), you can cache function calls through the class.
For example, you can create a function to perform the following tasks: Establish a database connection, perform a select on the database
Statement, gets the result of the search, and eventually returns the result as an array. You can then pass the call of the Cache_lite_function instance
The method caches the resulting array returned by the function so that the arrays can be read from the local cache rather than from the back-end database, which can significantly improve the performance of the application. Then, when you receive a notification that the cached data changes, you will use the
The drop method of the Cache_lite_function instance removes stale data from the cache.
Looking back at the example of this article, you might want to create two functions for your application to interact with the database: The first function will query the ORDERS table and return with the specified ID
order, and another function queries the Order_items table and returns the order item for that order. Listing 4 shows the Include Getorderfields function (the function accepts the order ID
and returns an getorderfields.php script that contains an associative array of some of the fields retrieved to the order.
Listing 4.
Gets the field for the specified order
<?php
File:getOrderFields.php
Require_once ' connect.php ';
function Getorderfields ($order _no) {
if (! $rsConnection = getconnection ()) {
return false;
}
$strSQL = "Select To_char (order_date) order_date, customer_id,
Order_total from ORDERS WHERE order_id =:order_no ";
$rsStatement = Oci_parse ($rsConnection, $strSQL);
Oci_bind_by_name ($rsStatement, ": Order_no", $order _no, 12);
if (!oci_execute ($rsStatement)) {
$err = Oci_error ();
Print $err [' message '];
Trigger_error (' Query failed: '. $err [' message ']);
http://www.bkjia.com/PHPjc/631001.html www.bkjia.com true http://www.bkjia.com/PHPjc/631001.html techarticle Building the client now that you've created registrations for orders and Order_items tables, we'll look at the client applications that access the orders stored in these tables and their order items ...