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

41 lines
857 B
PHP
Raw Normal View History

2010-08-03 12:28:07 +02:00
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">
2010-08-03 11:48:51 +02:00
<h1>Using Logger | dibi</h1>
2010-08-03 12:28:07 +02:00
2008-07-17 03:51:29 +00:00
<?php
require_once 'Nette/Debug.php';
2008-07-17 03:51:29 +00:00
require_once '../dibi/dibi.php';
date_default_timezone_set('Europe/Prague');
2008-07-17 03:51:29 +00:00
dibi::connect(array(
'driver' => 'sqlite',
'database' => 'data/sample.sdb',
'profiler' => TRUE,
2008-07-17 03:51:29 +00:00
));
2010-08-03 11:48:51 +02:00
// enable query logging to this file
dibi::getProfiler()->setFile('data/log.sql');
2008-07-17 03:51:29 +00:00
try {
$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', 38);
} catch (DibiException $e) {
echo '<p>', get_class($e), ': ', $e->getMessage(), '</p>';
}
2010-08-03 11:48:51 +02:00
// outputs a log file
echo "<h2>File data/log.sql:</h2>";
2008-07-17 03:51:29 +00:00
echo '<pre>', file_get_contents('data/log.sql'), '</pre>';