/** * Create a DB adapter * * @param ServiceLocatorInterface $services * @param string $name * @param string $requestedName * @return Adapter */ public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName) { $config = $this->getConfig($services); $adapter = new \BjyProfiler\Db\Adapter\ProfilingAdapter($config[$requestedName]); $adapter->setProfiler(new \BjyProfiler\Db\Profiler\Profiler()); if (isset($config[$requestedName]['options']) && is_array($config[$requestedName]['options'])) { $options = $config[$requestedName]['options']; } else { $options = array(); } $adapter->injectProfilingStatementPrototype($options); return $adapter; }
<?php $dbParams = (require 'dbParams.php'); return array('service_manager' => array('factories' => array('Zend\\Db\\Adapter\\Adapter' => function ($sm) use($dbParams) { $adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter(array('driver' => 'pdo', 'dsn' => 'mysql:dbname=' . $dbParams['database'] . ';host=' . $dbParams['hostname'], 'database' => $dbParams['database'], 'username' => $dbParams['username'], 'password' => $dbParams['password'], 'hostname' => $dbParams['hostname'], 'port' => $dbParams['port'])); $adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler()); $adapter->injectProfilingStatementPrototype(); return $adapter; }, 'entityManagerService' => function ($sm) { return $sm->get('Doctrine\\ORM\\EntityManager'); }), 'abstract_factories' => array('Zend\\Cache\\Service\\StorageCacheAbstractServiceFactory', 'Zend\\Db\\Adapter\\AdapterAbstractServiceFactory')), 'doctrine' => array('connection' => array('orm_default' => array('doctrine_type_mappings' => array('enum' => 'string'), 'driverClass' => 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver', 'params' => array('host' => $dbParams['hostname'], 'port' => $dbParams['port'], 'user' => $dbParams['username'], 'password' => $dbParams['password'], 'dbname' => $dbParams['database'])))));
<?php $dbParams = array('database' => 'devtmpad_apiuser', 'username' => 'devtmpad_apiuser', 'password' => 'cary5were', 'hostname' => 'localhost', 'options' => array('buffer_results' => true)); return array('service_manager' => array('factories' => array('Zend\\Db\\Adapter\\Adapter' => function ($sm) use($dbParams) { $adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter(array('driver' => 'pdo', 'dsn' => 'mysql:dbname=' . $dbParams['database'] . ';host=' . $dbParams['hostname'], 'database' => $dbParams['database'], 'username' => $dbParams['username'], 'password' => $dbParams['password'], 'hostname' => $dbParams['hostname'])); if (php_sapi_name() == 'cli') { $logger = new Zend\Log\Logger(); // write queries profiling info to stdout in CLI mode $writer = new Zend\Log\Writer\Stream('php://output'); $logger->addWriter($writer, Zend\Log\Logger::DEBUG); $adapter->setProfiler(new BjyProfiler\Db\Profiler\LoggingProfiler($logger)); } else { $adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler()); } if (isset($dbParams['options']) && is_array($dbParams['options'])) { $options = $dbParams['options']; } else { $options = array(); } $adapter->injectProfilingStatementPrototype($options); return $adapter; })));
/** * send a param 'aMigrationsDbConfig' to Zend\Db\Adapter\Adapter for setting dbconfig * @author feng * @return Migration */ protected function _setDbAdapter($aMigrationsDbConfig) { $oParameters = $this->getRequest()->getParams(); $oParameters->set('aMigrationsDbConfig', $aMigrationsDbConfig); $this->getRequest()->setParams($oParameters); $this->getServiceLocator()->setAllowOverride(true); $this->getServiceLocator()->setFactory('Zend\\Db\\Adapter\\Adapter', function ($sm) use($aMigrationsDbConfig) { // $aConfig['master'] = $oRe->getParam('aMigrationsDbConfig'); $aConfig['master'] = $aMigrationsDbConfig; $adapter = new \BjyProfiler\Db\Adapter\ProfilingAdapter(array('driver' => 'pdo', 'dsn' => $aConfig['master']['dsn'], 'username' => $aConfig['master']['username'], 'password' => $aConfig['master']['password'], 'driver_options' => $aConfig['master']['driver_options'])); $adapter->setProfiler(new \BjyProfiler\Db\Profiler\Profiler()); $adapter->injectProfilingStatementPrototype($aConfig['master']['driver_options']); return $adapter; }, true); }