Example #1
0
File: Db.php Project: allyse/allyse
 /**
  * Connect to DB, inherit credentials from constructor
  */
 private function connect()
 {
     $this->connectionId = 'DB_CONNECTION_' . md5(implode(',', $this->credentials));
     if (defined($this->connectionId) === FALSE) {
         $connection = dibi::connect($this->credentials, $this->connectionId);
         // Tracy panel
         if (TRACY === TRUE) {
             $panel = new Dibi\Bridges\Tracy\Panel();
             $panel->register($connection);
         }
         define($this->connectionId, TRUE);
     }
     $this->connection = dibi::getConnection($this->connectionId);
 }
Example #2
0
 /**
  * @param array $connectionParams
  */
 public static function init(array $connectionParams)
 {
     if (!dibi::isConnected()) {
         try {
             $connection = dibi::connect(array('driver' => $connectionParams['driver'], 'host' => $connectionParams['host'], 'dsn' => 'mysql:host=' . $connectionParams['host'] . ';dbname=' . $connectionParams['db'] . '', 'persistent' => true, 'username' => $connectionParams['user'], 'password' => $connectionParams['pass'], 'database' => $connectionParams['db'], 'charset' => isset($connectionParams['charset']) ? $connectionParams['charset'] : 'utf8', 'result' => array('detectTypes' => true, 'formatDate' => "Y-m-d", 'formatDateTime' => 'Y-m-d H:i:s'), 'profiler' => array('run' => true), 'flags' => MYSQLI_CLIENT_COMPRESS));
             $panel = new Dibi\Bridges\Tracy\Panel();
             $panel->register($connection);
         } catch (DibiException $e) {
             dd($e->getMessage());
             $view = Core_View::getInstance();
             $view->setLayoutFile('$maintenance/db_connect.phtml');
             $view->displayLayout();
             die;
         }
     }
 }
Example #3
0
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">

<style> html { background: url(data/arrow.png) no-repeat bottom right; height: 100%; } </style>

<h1>Tracy | dibi</h1>

<p>Dibi can log queries and dump variables to the <a href="http://tracy.nette.org">Tracy</a>.</p>

<?php 
if (@(!(include __DIR__ . '/../vendor/autoload.php'))) {
    die('Install dependencies using `composer install --dev`');
}
// enable Tracy
Tracy\Debugger::enable();
$connection = dibi::connect(array('driver' => 'sqlite3', 'database' => 'data/sample.s3db', 'profiler' => array('run' => TRUE)));
// add panel to debug bar
$panel = new Dibi\Bridges\Tracy\Panel();
$panel->register($connection);
// query will be logged
dibi::query('SELECT 123');
// result set will be dumped
Tracy\Debugger::barDump(dibi::fetchAll('SELECT * FROM customers WHERE customer_id < ?', 38), '[customers]');