1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-23 02:12:25 +01:00
php-dibi/examples/logger.php

68 lines
1.3 KiB
PHP
Raw Normal View History

2006-06-04 23:06:33 +00:00
<?php
require_once '../dibi/dibi.php';
// required since PHP 5.1.0
if (function_exists('date_default_timezone_set'))
date_default_timezone_set('Europe/Prague'); // or 'GMT'
2006-06-07 21:33:46 +00:00
// enable log to this file
2006-07-19 01:40:29 +00:00
dibi::$logFile = 'log.sql';
2006-06-04 23:06:33 +00:00
// append mode
dibi::$logMode = 'a';
// log all queries
dibi::$logAll = TRUE;
2006-06-04 23:06:33 +00:00
2006-06-04 23:06:33 +00:00
dibi::connect(array(
'driver' => 'sqlite',
'database' => 'sample.sdb',
2006-06-04 23:06:33 +00:00
));
// generate user-level errors
dibi::$throwExceptions = FALSE;
echo '<h1>User-level errors</h1>';
$res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] = %i', 1);
$res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < %i', 5);
$res = dibi::query('SELECT FROM [customers] WHERE [customer_id] < %i', 5);
echo "<br />See file ", dibi::$logFile;
// generate DibiException
dibi::$throwExceptions = TRUE;
echo '<h1>DibiException</h1>';
try {
2006-06-04 23:06:33 +00:00
$res = dibi::query('SELECT FROM [customers] WHERE [customer_id] < %i', 38);
2006-06-04 23:06:33 +00:00
} catch (DibiException $e) {
2006-06-04 23:06:33 +00:00
echo '<pre>', $e, '</pre>';
2006-06-04 23:06:33 +00:00
echo '<h2>$e->getSql()</h2>';
$sql = $e->getSql();
echo "SQL: $sql\n";
2006-06-04 23:06:33 +00:00
echo '<h2>$e->getDbError()</h2>';
$error = $e->getDbError();
echo '<pre>';
print_r($error);
echo '</pre>';
2006-06-04 23:06:33 +00:00
}