Build a client
Now, you have
The table has been created for registration. Next we will learn how to use the change notification for the client applications that access the orders stored in these tables and their order items. To this end, you can build
PHP
The application caches the query results for the above tables and takes corresponding actions to respond to notifications about changes to these tables (from
DatabaseThe server receives these notifications ). A simple method is to use
PEAR: Cache_Lite package, which provides you with a reliable mechanism to keep cache data up-to-date. In particular, you can use Cache_Lite_Function
Class (PEAR: Part of the Cache_Lite package), through which you can cache function calls.
For example, you can create a function to execute the following tasks: create a database connection, and execute select
Statement, get the search result, and finally return the result in an array. Then, you can use the call function of the Cache_Lite_Function instance
The method caches the result arrays returned by the function so that these arrays can be read from the local cache rather than from the backend database, which can significantly improve the application performance. Then, you will use
The drop method of the Cache_Lite_Function instance deletes expired data in the cache.
Looking back at the example in this article, you may want to create two functions for the application to interact with the database: the first function will query the ORDERS table and return
And the other function will query the ORDER_ITEMS table and return the order items of the order. "Listing 4" shows the getOrderFields function (this function accepts the order ID
Return the getOrderFields. php script that contains the associated array of some fields in the retrieved order.
Listing 4.
Obtains the field of a 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']);