Example #1
1
 /**
  *
  * @param PWECore $PWE
  * @param bool $forceNewConnection
  * @param string $alias
  * @return Connection
  * @throws DBALException
  */
 public static function getConnection(PWECore $PWE, $forceNewConnection = false, $alias = null)
 {
     if (!$forceNewConnection && self::$connection[$alias]) {
         PWELogger::debug('Used cached connection');
         return self::$connection[$alias];
     }
     $settings = $PWE->getModulesManager()->getModuleSettings(self::getClass());
     $connections = $settings['!c']['connection'];
     $ix = PWEXMLFunctions::findNodeWithAttributeValue($connections, 'alias', $alias);
     if ($ix < 0) {
         throw new \InvalidArgumentException("Alias {$alias} not found in database configs");
     }
     $params = $connections[$ix]['!a'];
     $config = new Configuration();
     $config->setSQLLogger(new PWEDoctrineLogger($alias ? $alias : ''));
     PWELogger::debug("Getting connection: %s", $params);
     self::$connection[$alias] = DriverManager::getConnection($params, $config);
     return self::$connection[$alias];
 }
Example #2
0
 /**
  * Get an instance of a DBAL Connection
  *
  * @param sting $name the connection name
  * @return Doctrine\DBAL\Connection
  */
 public function newConnection()
 {
     $configuration = new DBAL\Configuration();
     $logger = new MSQLLogger($this);
     $configuration->setSQLLogger($logger);
     return DBAL\DriverManager::getConnection($this->config, $configuration);
 }
Example #3
0
 /**
  * setup configuration for Doctrine Dbal.
  * 
  * @param array $db_config array config for override the default configuration.
  */
 public function setupConfigurationDbal(array $db_config = [])
 {
     $dbal_config = new Configuration();
     if (empty($db_config)) {
         //setup connection configuration.
         $config = new SystemConfig();
         $config->load('db');
         $db_params = $config->get('ALL', 'db');
         unset($config, $db_params['table_prefix']);
     } else {
         $db_params = $db_config;
         unset($db_params['table_prefix']);
     }
     $dbal_config->setSQLLogger(new \System\Libraries\Db\Logger());
     try {
         $this->Conn = DriverManager::getConnection($db_params, $dbal_config);
         $this->Conn->connect();
     } catch (\Doctrine\DBAL\DBALException $e) {
         http_response_code(500);
         echo $e->getMessage();
         exit;
     }
     $this->Conn->setFetchMode(\PDO::FETCH_OBJ);
     unset($dbal_config, $db_params);
 }
Example #4
0
 public function register()
 {
     $this->container->add('service.dbal.connection', function () {
         $connectionParams = $this->container->get('config')['dbal']['connection']['params'];
         $config = new Configuration();
         $config->setSQLLogger(new DebugStack());
         return DriverManager::getConnection($connectionParams, $config);
     });
 }
Example #5
0
File: db.php Project: 453111208/bbc
 protected static function getFacadeAccessor()
 {
     if (!static::$__db) {
         $configuration = new Configuration();
         $logger = new base_database_logger();
         $configuration->setSQLLogger($logger);
         static::$__db = new base_database_manager($configuration);
     }
     return static::$__db;
 }
 public function getConn()
 {
     if (isset(static::$connection)) {
         return static::$connection;
     }
     //set up a special logger that counts queries here
     $configuration = new Configuration();
     $configuration->setSQLLogger($this->getSQLLogger());
     static::$connection = DriverManager::getConnection($this->getConnectionParams(), $configuration);
     return static::$connection;
 }
 /**
  * Get DBAL configuration object
  * @param boolean $devMode Development mode enables a query logger
  * @return Configuration
  */
 protected function getConfig($devMode)
 {
     $config = new Configuration();
     if ($devMode) {
         //Create logger
         $debugStack = new DebugStack();
         $config->setSQLLogger($debugStack);
         $this->app->instance('dbal.debug', $debugStack);
     }
     return $config;
 }
Example #8
0
 public function register()
 {
     $this->container['dbal_connection_params'] = function () {
         return $this->container->get('config')['dbal']['connection']['params'];
     };
     $this->container['db_connection'] = function () {
         $connectionParams = $this->container->get('dbal_connection_params');
         $debugStack = new DebugStack();
         $config = new Configuration();
         $config->setSQLLogger($debugStack);
         return DriverManager::getConnection($connectionParams, $config);
     };
 }
 /**
  * @param ServiceLocatorInterface $serviceLocator
  * @param Configuration           $config
  */
 public function setupDBALConfiguration(ServiceLocatorInterface $serviceLocator, Configuration $config)
 {
     $options = $this->getOptions($serviceLocator);
     $config->setResultCacheImpl($serviceLocator->get($options->resultCache));
     $config->setSQLLogger($options->sqlLogger);
     foreach ($options->types as $name => $class) {
         if (Type::hasType($name)) {
             Type::overrideType($name, $class);
         } else {
             Type::addType($name, $class);
         }
     }
 }
 /**
  * Creates a RepositoryFactory
  *
  * @param   Container $container The container
  *
  * @return  RepositoryFactory
  */
 public function createRepositoryFactory(Container $container)
 {
     $config = parse_ini_file(JPATH_ROOT . '/config/database.ini', true);
     $configuration = new Configuration();
     // Add logger
     $logger = new DebugStack();
     $configuration->setSQLLogger($logger);
     $connection = DriverManager::getConnection(['url' => $config['databaseUrl']], $configuration);
     $transactor = new DoctrineTransactor($connection);
     $repositoryFactory = new RepositoryFactory($config, $connection, $transactor);
     if ($container->has('dispatcher')) {
         $repositoryFactory->setDispatcher($container->get('dispatcher'));
     }
     return $repositoryFactory;
 }
Example #11
0
 /**
  * Creates a new connection to the database
  *
  * @param Context $context
  * @param array|Config $db_data
  */
 public function __construct(Context $context, $db_data = [])
 {
     parent::__construct($context);
     // load the defaults if the config object has been passed
     if ($db_data instanceof Config) {
         $db_data = $db_data->get('foolz/foolframe', 'db', 'default');
     }
     $config = new Configuration();
     $config->setSQLLogger(new DoctrineLogger($context));
     $data = ['dbname' => $db_data['dbname'], 'user' => $db_data['user'], 'password' => $db_data['password'], 'host' => $db_data['host'], 'driver' => $db_data['driver']];
     if ($db_data['driver'] == 'pdo_mysql') {
         $data['charset'] = $db_data['charset'];
     }
     $this->prefix = $db_data['prefix'];
     $this->connection = DriverManager::getConnection($data, $config);
 }
 /**
  * @param ContainerInterface $container
  * @param Configuration      $config
  */
 public function setupDBALConfiguration(ContainerInterface $container, Configuration $config)
 {
     $options = $this->getOptions($container);
     $config->setResultCacheImpl($container->get($options->resultCache));
     $sqlLogger = $options->sqlLogger;
     if (is_string($sqlLogger) and $container->has($sqlLogger)) {
         $sqlLogger = $container->get($sqlLogger);
     }
     $config->setSQLLogger($sqlLogger);
     foreach ($options->types as $name => $class) {
         if (Type::hasType($name)) {
             Type::overrideType($name, $class);
         } else {
             Type::addType($name, $class);
         }
     }
 }
Example #13
0
 public function register(Neptune $neptune)
 {
     $neptune['db.config'] = function ($neptune) {
         $config = $neptune['config']->get('neptune.database', []);
         if (empty($config)) {
             throw new ConfigKeyException('Database configuration is empty');
         }
         return $config;
     };
     $neptune['dbs'] = function ($neptune) {
         $dbs = new Container();
         $config = $neptune['db.config'];
         //register types
         if (isset($config['_types'])) {
             foreach ($config['_types'] as $name => $classname) {
                 Type::addType($name, $classname);
             }
             unset($config['_types']);
         }
         foreach ($config as $name => $config) {
             $dbs[$name] = function ($dbs) use($config, $neptune) {
                 $configuration = new Configuration();
                 if (isset($config['logger'])) {
                     $configuration->setSQLLogger(new PsrSqlLogger($neptune[$config['logger']]));
                 }
                 return DriverManager::getConnection($config, $configuration);
             };
         }
         return $dbs;
     };
     //shortcut for the first database
     $neptune['db'] = function ($neptune) {
         $config = $neptune['db.config'];
         reset($config);
         $default = key($config);
         return $neptune['dbs'][$default];
     };
 }
Example #14
0
 /**
  * Initialize the panel (set a SQL logger)
  *
  * @param Configuration $doctrineConfiguration The doctrine configuration
  * @param string        $name                  The name of the panel (Useful if you watch multiple Doctrine instance)
  */
 public function __construct(Configuration $doctrineConfiguration, $name = '')
 {
     $doctrineConfiguration->setSQLLogger(new DebugStack());
     $this->doctrineConfiguration = $doctrineConfiguration;
     $this->name = $name;
 }
 public function setupDBALConfiguration(ServiceLocatorInterface $serviceLocator, Configuration $config)
 {
     $options = $this->getOptions($serviceLocator);
     $config->setResultCacheImpl($serviceLocator->get($options->resultCache));
     $config->setSQLLogger($options->sqlLogger);
 }
Example #16
0
 public function setSqlLogger(Doctrine\DBAL\Logging\SQLLogger $sqlLogger)
 {
     $this->entityManagerConfiguration->setSQLLogger($sqlLogger);
 }
Example #17
0
 /**
  * @throws \Doctrine\DBAL\DBALException
  */
 protected function connect()
 {
     $config = new DBAL\Configuration();
     if ($this->appMode === ApplicationMode::DEVELOPMENT) {
         $config->setSQLLogger(new SQLLogger($this->logger));
     }
     $config->setResultCacheImpl($this->cacheDriverFactory->create('db-queries'));
     return DBAL\DriverManager::getConnection($this->connectionParams, $config);
 }
Example #18
0
 /**
  * @param array
  * @param \Doctrine\Common\EventManager|NULL
  * @return \Doctrine\DBAL\Connection
  */
 public static function createConnection(array $params, EventManager $evm)
 {
     $panel = NULL;
     $config = new Configuration();
     if (isset($params['debugger']) && $params['debugger'] === TRUE) {
         $panel = new ConnectionPanel();
         if (Debugger::$bar) {
             Debugger::$bar->addPanel($panel);
         }
         Debugger::$blueScreen->addPanel(array($panel, 'renderException'));
         $config->setSQLLogger($panel);
     } else {
         Debugger::$blueScreen->addPanel('Nette\\Database\\Diagnostics\\ConnectionPanel::renderException');
     }
     $cfg = $params['connection'];
     $connection = DriverManager::getConnection($cfg, $config, $evm);
     if ($connection->getDatabasePlatform()->getName() == 'mysql' && isset($cfg['charset'])) {
         $evm->addEventSubscriber(new MysqlSessionInit($cfg['charset'], $cfg['collation']));
     }
     if ($panel && $panel->doExplains) {
         $panel->setConnection($connection);
     }
     return $connection;
 }
Example #19
0
 /**
  * @return \Doctrine\DBAL\Connection
  */
 public function getConnection()
 {
     $config = new Configuration();
     $config->setSQLLogger(new SqlLogger($this->get('logger')));
     $params = array('dbname' => $this->get('config')->get('psx_sql_db'), 'user' => $this->get('config')->get('psx_sql_user'), 'password' => $this->get('config')->get('psx_sql_pw'), 'host' => $this->get('config')->get('psx_sql_host'), 'driver' => 'pdo_mysql');
     return DriverManager::getConnection($params, $config);
 }