Finally, let's customize an application to comprehensively explain the overall framework of the PEAR buffering mechanism. We define a class called MySQL_Query_Cache to cache SELECT query results. We first define the class variables: '.', 'filename_prefix' => 'cache_'), $expires = 3600) { $this->Cache($container, $container_options); $this->expires = $ expires; } function _MySQL_Query_Cache() { if (is_resource($this->connection)) { mysql_close($this->connection); } $this->_Cache(); } } ?> Before we start, we need some Auxiliary functions. function connect($hostname, $username, $password, $database) { $this->connection = mysql_connect($hostname, $username, $password) or trigger_error('Database connection failed!', E_USER_ERROR); mysql_select_db($database , $this->connection) or trigger_error('Database selection failed!', E_USER_ERROR); } function fetch_row() { if ($this->cursor result)) { return $this->result[$this- >cursor++]; } else { return false; } } function num_rows() { return sizeof($this->result); } ?> Let’s see how to buffer: result = $this->get($cache_id , 'mysql_query_cache'); if ($this->result == NULL) { // Buffer loss $this->cursor = 0; $this->result = array(); if (is_resource($this->connection) ) { // Use mysql_unbuffered_query() if possible if (function_exists('mysql_unbuffered_query')) {$result = mysql_unbuffered_query($query, $this->connection); } else {$result = mysql_query($query, $this-> connection); } // Fetch all query results while ($row = mysql_fetch_assoc($result)) {$this->result[] = $row; } // Release the MySQL result resource mysql_free_result($result); // Put the result Buffer $this->save($cache_id, $this->result, $this->expires, 'mysql_query_cache'); } } } else { // No query results, no buffering required return mysql_query($query, $this- >connection); } } ?> Example 3: Using MySQL query cache connect('hostname', 'username', 'password', 'database'); $cache->query('select * from table') ; while ($row = $cache->fetch_row()) { echo '