Building the Client
Now that you have created registrations for the ORDERS and ORDER_ITEMS
tables, let’s take a look at the client application that accesses the orders and their line items stored in these tables. Use change notifications. To do this, you can build a PHP
application that will cache query results against the above tables and take appropriate actions in response to changes made to those tables notifications (received from the database server). An easy way is to use the
PEAR::Cache_Lite package, which provides you with a reliable mechanism to keep cache data up to date. In particular, you can use the Cache_Lite_Function
class (part of the PEAR::Cache_Lite package), which allows you to cache function calls.
For example, you can create a function that performs the following tasks: establishes a database connection, executes a select
statement against the database, obtains the search results, and finally returns the results as an array. You can then cache the result arrays returned by the function via the call
method of the Cache_Lite_Function instance so that these arrays can be read from the local cache instead of from the backend database, which can significantly improve the performance of your application. Then, when notified of changes to the cached data, you would use the drop method of the
Cache_Lite_Function instance to delete the expired data from the cache.
Looking back at the example in 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 the order with the specified ID
, and the other The function queries the ORDER_ITEMS table and returns the line items for that order. Listing 4 shows the getOrderFields.php script that contains the getOrderFields function, which accepts an order ID
and returns an associative array containing some of the fields of the retrieved order.
Listing 4.
Get the fields of the specified order
<?php <br>//File:getOrderFields.php <br>require_once 'connect.php'; <br>function getOrderFields($order_no) { <br>if (!$rsConnection = GetConnection()){ <br>return false; <br> } <br>$strSQL = "SELECT TO_CHAR(ORDER_DATE) ORDER_DATE, CUSTOMER_ID, <br>ORDER_TOTAL FROM ORDERS WHERE order_id =:order_no"; <br>$rsStatement = oci_parse($rsConnection,$strSQL); <br>oci_bind_by_name($rsStatement, ":order_no", $order_no, 12); <br>if (!oci_execute($rsStatement)) { <br>$err = oci_error(); <br>print $err['message']; <br>trigger_error('Query failed:' . $err['message']) ; <br> <p align="left"></p><div style="display:none;"> <span id="url" itemprop="url">http://www.bkjia.com/PHPjc/631001.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http: //www.bkjia.com/PHPjc/631001.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">Building the Client Now that you have created registrations for the ORDERS and ORDER_ITEMS tables, we will look at accessing these tables. Client application for orders and their line items stored in...</span> </div> <div class="art_confoot"></div>