Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
Database Tools
SQL Scripts & Samples
» Database Forum
» Slideshows
» Sitemap
Free Newsletters:
News Via RSS Feed

follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles


Posted Aug 27, 2002

Faking It - Simulated Database Queries - Page 5

By Staff

Cached Queries

Often we store things in databases just because it's a handy, central location. If you have a list of states and their abbreviations for a dropdown list it makes a lot of sense to put it in the database and be able to grab it when you need it. However, that data is rarely updated and is can be a performance hit to query for it. QuerySim can help take some of the load off your database by 'caching' the data in a file.

if (!isset($states)) {
$conn DB::connect(querysim);
$states $conn->query('
        // and so on...

PHP does the work and your database gets a break.

Form Reuse

Forms may be reused by running QuerySim with NULL data before displaying the form in 'add' mode. In 'update' mode we'll run the real query.

if ($mode == 'add') {
$dsn 'querysim';
$sql 'userID,firstName,lastName,userGroups
    } else {
$dsn 'mysql://selectuser:selectpw@dbserver/appdatabase';
$sql "SELECT
                    userID = '$userID'"
$conn DB::connect($dsn);
// error checking removed for clarity
$user $conn->query($sql);

<form name="user" action="submit" method="get">
printf('<input name="userID" type="Hidden" value="%s" />'$userData['userID']);
printf('First Name: <input name="firstName" type="Text" value="%s" /><br />'$userData['firstName']);
printf('Last Name: <input name="lastName" type="Text" value="%s" /><br />'$userData['lastName']);
printf('User Groups: <input name="userGroups" type="Text" value="%s" /><br />'$userData['userGroups']);
printf('<input type="Submit" value="%s user" />'$mode);

As you can see, because the display code doesn't change, QuerySim makes reusing forms a trivial matter.

PHP Archives

Comment and Contribute


(Maximum characters: 1200). You have characters left.