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

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
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 6

By Staff

Advanced PHP QuerySim

The original ColdFusion QuerySim wasn't always this simple to use, it required the QuerySim text to reside in a separate *.sim file that it read in before parsing. Bert Dawson modified that version so the developer could put the QuerySim text inline, making it much easier to use and also retained backward compatibility to read external files. PHP QuerySim can also read external files but takes it a couple steps further than the ColdFusion version.

External Files

Recall the syntax for the PEAR DB connect string:


This time we are going to connect to a data source. Well, sort of. The path and name of an external file is going to be our database in the connect string. PEAR DB uses different characters in the string to parse out which user string belongs to which parameter. To set any of the parameters, phptype must be followed by a colon and two forward slashes (://). A database name (our external file) must follow a forward slash (/) character. So, we use the following syntax:


Note that three forward slashes precede the file path! A colon and two forward slashes (://) for the parameter separator and one forward slash (/) to indicate that what follows is a 'database'.

These will also work:

querysim:///../../../userGroups.sim querysim:///c:/netlogs/webserver.log

Windows file delimiters may be forward or back slashes.

When calling an external file the text in query() is ignored. However, if the parameter isn't passed at all a Warning is raised by PEAR DB. Use an empty string or a dummy string to prevent a warning from being thrown:

$conn->query('read from file');

When the option, persistent, is set to true, QuerySim will emulate a persistent database connection by keeping the file open from connect() until disconnect().

Escape Character

Characters used as delimiters may be output by escaping them using a back slash. For example:


would output (using our earlier display code):

100, St|an Cox, 33

PHP Archives

Comment and Contribute


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