Run-time Options
QuerySim has three options that may be set at run-time:
columnDelim
- Sets the delimiter for column names.
- Default is a comma (
,).
dataDelim
- Sets the delimiter for data lines.
- Default is a pipe (
|).
eolDelim
- Sets the delimiter for an end-of-line.
- Default is a Windows carriage return/line feed (ASCII decimal characters 13 and 10) and may, of course, be adjusted for -nix and Mac files.
All of these options may be set to virtually any character or combination of characters. The escape character, back slash (\), may not be used. Attempting to set any of the delimiters to back slash by using an escaped back slash (\\) will throw an error.
Non-printing characters may be set using their ASCII code or PHP alias. For example, a tab may be expressed as 'chr(9)' or '\t'.
External File Example
Suppose we want pull a comma delimited server log for a web based administration tool:
<?php
require_once 'DB.php';
$dsn = "querysim:///c:/weblogs/webserver.log";
$conn = DB::connect($dsn, array('persistent'=>true, 'dataDelim'=>','));// notice that we change the dataDelim to a ','
if (DB::isError($conn)) {
die ('Cannot connect: '.$conn->getMessage()."\n<br />\n<pre>".$conn->getUserInfo()."\n</pre>\n<br />");
}
$user = $conn->query('read from file');
if (DB::isError($user)){
die ('Database Error: '.$user->getMessage()."\n<br />\n<pre>".$user->getUserInfo()."\n</pre>\n<br />");
}
$conn->disconnect();
?>
Using a sub-string search in a conditional, we could easily display only certain types of errors, 404s for example.