Improve PHP performance by caching database results (4)

Source: Internet
Author: User
Tags arrays pear php script
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']);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.