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.
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:
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
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