예제 #1
0
파일: Db.php 프로젝트: 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);
 }
예제 #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;
         }
     }
 }
예제 #3
0
파일: tracy.php 프로젝트: jakubmacek/dibi
<!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]');