First, grab a copy of PHP QuerySim from David Huyck's bombusbee.com, 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:
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
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.*
would return a record set with 1 row containing 4 columns of information about Stan Cox.
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.