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 7

By Staff

Run-time Options

QuerySim has three options that may be set at run-time:

Sets the delimiter for column names.
Default is a comma (,).
Sets the delimiter for data lines.
Default is a pipe (|).
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:

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 (
    die (
'Database Error: '.$user->getMessage()."\n<br />\n<pre>".$user->getUserInfo()."\n</pre>\n<br />");


Using a sub-string search in a conditional, we could easily display only certain types of errors, 404s for example.

PHP Archives

Comment and Contribute


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