예제 #1
0
 public static function initDb()
 {
     $config = \Phalcon\DI::getDefault()->get('config');
     $connection = new \Phalcon\Db\Adapter\Pdo\Mysql($config->database->toArray());
     if (getenv('APPLICATION_ENV') == 'devel') {
         $eventsManager = new \Phalcon\Events\Manager();
         $eventsManager->attach('db', function ($event, $connection) {
             if ($event->getType() == 'beforeQuery') {
                 //Start a profile with the active connection
                 error_log($connection->getSQLStatement() . "\n" . json_encode($connection->getSQLVariables()));
             }
         });
         $connection->setEventsManager($eventsManager);
     }
     return $connection;
 }
예제 #2
0
파일: index.php 프로젝트: ChainBoy/phalcon
     $url->setBaseUri($di->get("config")->get("common")["baseuri"]);
     return $url;
 };
 $di["session"] = function () {
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     return $session;
 };
 $di["db"] = function () use($di) {
     $config = $di->get("config")->get("common")["db"];
     $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config["host"], "username" => $config["username"], "password" => $config["password"], "dbname" => $config["dbname"], "charset" => $config["charset"]));
     $eventsManager = new \Phalcon\Events\Manager();
     $dblog = $di->get("config")->get("common")["dblog"];
     $logger = new \Phalcon\Logger\Adapter\File(__DIR__ . $dblog);
     $eventsManager->attach('db:beforeQuery', function ($event, $connection) use($logger) {
         $sqlVariables = $connection->getSQLVariables();
         if (count($sqlVariables)) {
             $logger->log($connection->getSQLStatement() . ' ' . join(', ', $sqlVariables), \Phalcon\Logger::INFO);
         } else {
             $logger->log($connection->getSQLStatement(), \Phalcon\Logger::INFO);
         }
     });
     $connection->setEventsManager($eventsManager);
     return $connection;
 };
 $di["dbBackupTool"] = function () use($di) {
     $config = $di->get("config")->get("common")["db"];
     return new \Phalcon_wifi\Common\Ext\DBManager($config["username"], $config["password"], $config["host"], $config["dbname"]);
 };
 $di["filter"] = function () {
     return new \Phalcon_wifi\Common\Ext\Filter();