Пример #1
0
 public static function connect($settings = array(), $connection_name = null)
 {
     $config = Environment::getConfig();
     foreach ($config['database'] as $connection_name => $settings) {
         try {
             dibi::connect($settings, $connection_name);
             if ($settings['profiler'] == true) {
                 dibi::getProfiler()->setFile(APP_DIR . '/log/db.txt');
             }
         } catch (DibiException $e) {
             echo get_class($e), ': ', $e->getMessage(), "\n";
         }
     }
 }
Пример #2
0
<h1>dibi logger example</h1>
<?php 
require_once 'Nette/Debug.php';
require_once '../dibi/dibi.php';
date_default_timezone_set('Europe/Prague');
dibi::connect(array('driver' => 'sqlite', 'database' => 'sample.sdb', 'profiler' => TRUE));
// enable log to this file
dibi::getProfiler()->setFile('log.sql');
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>';
}
echo "<h2>File log.sql:</h2>";
echo '<pre>', file_get_contents('log.sql'), '</pre>';
Пример #3
0
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">

<h1>Using Logger | dibi</h1>

<?php 
require_once 'Nette/Debug.php';
require_once '../dibi/dibi.php';
date_default_timezone_set('Europe/Prague');
dibi::connect(array('driver' => 'sqlite', 'database' => 'data/sample.sdb', 'profiler' => TRUE));
// enable query logging to this file
dibi::getProfiler()->setFile('data/log.sql');
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>';
}
// outputs a log file
echo "<h2>File data/log.sql:</h2>";
echo '<pre>', file_get_contents('data/log.sql'), '</pre>';