phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


ADOdb: Caching of Recordset

Tag: adodb, database, database layer   Category: PHP Database
post: 30 Oct 2007 read: 1,780


It's cute feature in adodb, caching of recordset. It will fast result your query.

Several method cache recordset:

CacheExecute()
CachePageExecute()
CacheSelectLimit()

CacheExecute()

Similar to Execute, except that the recordset is cached for $secs2cache seconds in the $ADODB_CACHE_DIR directory. If CacheExecute() is called again with the same parameters, same database, same userid, same password, and the cached recordset has not expired, the cached recordset is returned


    include('adodb.inc.php'); 
    include('tohtml.inc.php'); 
    $ADODB_CACHE_DIR = '/usr/local/ADOdbcache'; 
    $conn = &ADONewConnection('mysql'); 
    $conn->PConnect('localhost','userid','password','database'); 
    $rs = $conn->CacheExecute(15, 'select * from table'); 
    # cache 15 secs 

CachePageExecute()

formula:


CachePageExecute($secs2cache, $sql, $nrows, $page, $inputarr=false) 

Used for pagination of recordset. $page is 1-based.


    include_once('adodb.inc.php'); 
    include_once('adodb-pager.inc.php'); 
    session_start(); 

    $db = NewADOConnection('mysql'); 
    $db->Connect('localhost','root','','xphplens'); 
    $sql = "select * from adoxyz "; 

    $pager = new ADODB_Pager($db,$sql); 
    $pager->Render($rows_per_page=5); 

CacheSelectLimit()

Formula:


CacheSelectLimit([$secs2cache,] $sql, $numrows=-1,$offset=-1,$inputarr=false)

Similar to SelectLimit, except that the recordset returned is cached for $secs2cache seconds in the $ADODB_CACHE_DIR directory.


 $conn->Connect(...); 
    $conn->cacheSecs = 3600*24; // cache 24 hours 
    $rs = $conn->CacheSelectLimit('select * from table',10); 

I have done some benchmarks and found that they vary so greatly that it's better to talk about when caching is of benefit. When your database server is much slower than your Web server or the database is very overloaded then ADOdb's caching is good because it reduces the load on your database server. If your database server is lightly loaded or much faster than your Web server, then caching could actually reduce performance (note from manual).



Series this article:
ADOdb: Introduction
ADOdb: Connection Statement
ADOdb: Advance Select Statement
ADOdb: How to show tables
ADOdb: How to show fields
ADOdb: How to show databases
ADOdb: Caching of Recordset
ADOdb: Recordset to HTML
ADOdb: Multi Database Connection
ADOdb: Data Dictionary
ADOdb: Quick Export Data
ADOdb: Insert data style
ADOdb: Replace Data
ADOdb: Log Query
PHP ADOdb: Understanding Pivot Table For Reporting
PHP ADOdb: Creating Pivot Table
PHP ADOdb: Creating Query to Build Pivot Table

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting