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

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

PHP

Posted Aug 27, 2002

Faking It - Simulated Database Queries - Page 7

By DatabaseJournal.com Staff

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.



PHP Archives

Comment and Contribute

 


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