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 2

By Staff


First, grab a copy of PHP QuerySim from David Huyck's, jumping off point for all things PHP Fusebox. (Thanks, David!)

Next, check to see if you already have PEAR DB installed. If you're not sure, create a file called testdb.php and put this in it:

require_once 'DB.php';

Browse to the file and if you didn't get an error, you are all set. If you got a Fatal Error you need to contact your system administrator and have them install PEAR DB and/or add the PEAR directory to PHP Server's include_path.

Once PEAR DB is available, simply place querysim.php in the /pear/DB directory with the other database drivers and you're all done.

QuerySim Text Syntax

QuerySim syntax is pretty simple and is similar to a comma separated value file. (In fact PHP QuerySim is capable of reading CSV files, more on that later.)

  • The first line is a comma (,) delimited list of query columns.
  • Second (and any subsequent lines) is pipe (|) delimited data used to populate the query.
  • An empty data column is denoted by the string 'null' or an empty column. The value stored in the record set is actually a zero length string, rather than a true NULL.
  • A carriage return/line feed denotes an end-of-line.*

For instance:


would return a record set with 1 row containing 4 columns of information about Stan Cox.



or this:


would do the same, except the lastName field would be empty.

*QuerySim's end-of-line (EOL) defaults to a Windows format carriage return/line feed, on -nix and Macintosh file systems the EOL may need to be modified. Changing delimiters at run-time will be discussed later in Advanced PHP QuerySim.

Faking It With PHP QuerySim

Now that you know the syntax for QuerySim, it is no more difficult to use with PEAR DB than a real database. If you are unfamiliar with PEAR DB, Allan Kent wrote a great primer that I suggest you take a minute to read.

PHP Archives

Comment and Contribute


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



Thanks for your registration, follow us on our social networks to keep up-to-date