Database
  Home arrow Database arrow Page 11 - Accessing Databases with ADODB
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

Accessing Databases with ADODB
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 37
    2004-08-02

    Table of Contents:
  • Accessing Databases with ADODB
  • Connecting, Queries and Quoting
  • Introducing Record Sets
  • Retrieving Multiple Rows
  • Understanding Error Handling
  • Generating HTML
  • More HTML Generation
  • Printing
  • Splitting Data Across Multiple Pages
  • Pivot Tables
  • Caching
  • Exporting Data

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Accessing Databases with ADODB - Caching


    (Page 11 of 12 )

    ADODB has a built-in caching mechanism that you can invoke using a special function to run your queries. Instead of calling Execute(), use CacheExecute() for a query. The first argument to CacheExecute() is how many seconds you want the result of the query cached. The rest of the arguments are the same as Execute():

    // Cache this recordset for 10 seconds
    $rs = $conn->CacheExecute(10,'SELECT flavor, price,
                     calories FROM ice_cream');

    Record sets are cached in individual files. The filename is calculated from the SQL query passed to CacheExecute() and information from the connection handle: the database type, the database name, and the database user. For the purpose of calculating a cache filename, these values are all case-sensitive. If you call CacheExecute() twice with two queries that are identical to the database but have different spacing or capitalization, the second call to CacheExecute() doesn’t retrieve the data from the cache—it sends the query to the database. The query, database type, database name, and database user must be exactly the same for arecord set to be retrieved from the cache.

    By default, ADODB puts its cache files in subdirectories it creates under the /tmp directory. You can change this base cache directory by setting the value of the global variable $ADODB_CACHE_DIR to your chosen directory name. ADODB’s caching behavior requires you to consider the permissions on the cache files and directories carefully to make sure that sensitive data is not exposed. First, the user that your Web server is running as must have write permission to $ADODB CACHE_DIR. The cache subdirectories created under $ADODB_CACHE_DIR have their permissions set so that the Web server user and group can read and write to them, but other users have only execute permission. This opens two potential security holes. First, if a user can guess the name of a cache file, then they can read the data inside it. Second, if you are in a shared-hosting environment where all users’ sites are served by the same Web server process, any user can read all of the cache files. To deal with these potential security risks, set $ADODB_CACHE_DIR to a new directory that other users can’t access. Each user in a shared hosting environment should ideally have their own space in the file system that the Web server serving their site can read but other Web servers can’t.

    Record sets expire from the cache when their time, as specified to CacheExecute(), expires, but you have two ways to explicitly expire a record set. The first is to call CacheExecute() with a time value of 0. This forces ADODB to send the query to the database and overwrite any possibly cached values with new results. The second way is to call the CacheFlush() method. With no arguments, CacheFlush() removes everything from the cache. If you pass an SQL query to CacheFlush(), it removes from the cache the record set that corresponds to that query.

    Both CacheExecute() and CacheFlush() calculate cache filenames based on the SQL query after any placeholders have been replaced. Both the query that contains placeholders and the placeholder array must be identical for two queries to have the same cache file:

    // Get inexpensive ice cream
    $rs = $conn->CacheExecute(10, 'SELECT flavor FROM ice_cream
                  WHERE price < ?', array(4));
    // Purge the query from the cache
    $conn->CacheFlush('SELECT flavor FROM ice_cream
                         WHERE price < ?',array(4));

    This is from Essential PHP Tools, by David Sklar (Apress, ISBN 1590592808). Check it out at your favorite bookstore today. Buy this book now.

    More Database Articles
    More By Apress Publishing


       · i want the programming code for the add delete update useing the adodb ontrols.
     

    DATABASE ARTICLES

    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005
    - Manipulating ADO Recordsets





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway