private static function _createAdapter() { $adapter = self::_getZendAdapterName(WeFlex_Application::GetInstance()->config->db->adapter); /** * $TODO check the following validate */ $database = WeFlex_Application::GetInstance()->config->db->database; $username = WeFlex_Application::GetInstance()->config->db->user; $password = WeFlex_Application::GetInstance()->config->db->pwd; $host = WeFlex_Application::GetInstance()->config->db->host; /** * @todo if the adapter is exsit , we could not create it , and get it from registry */ $zendAdapter = Zend_Db::factory($adapter, array('host' => $host, 'username' => $username, 'password' => $password, 'dbname' => $database)); /** * hack for debugger; */ if (WeFlex_Application::GetInstance()->config->db->usefirephp) { $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $zendAdapter->setProfiler($profiler); } $zendAdapter->getConnection(); $zendAdapter->query("SET NAMES 'utf8'"); return $zendAdapter; }
protected function _initDbProfiler() { $this->bootstrap('db'); $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $this->getPluginResource('db')->getDbAdapter()->setProfiler($profiler); }
public function run() { // Lade Konfig $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV); Zend_Registry::set('config', $config); // Erstelle DB Adapter $db = Zend_Db::factory($config->db); Zend_Registry::set('db', $db); Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Registry::get('db')); if (APPLICATION_ENV !== 'production') { $profiler = new Zend_Db_Profiler_Firebug('All Database Queries:'); $profiler->setEnabled(true); $db->setProfiler($profiler); } $resourceLoader = new Zend_Loader_Autoloader_Resource(array('basePath' => APPLICATION_PATH, 'namespace' => '')); $resourceLoader->addResourceType('plugins', 'plugins', 'Plugins'); if (PHP_SAPI != 'cli') { $front = Zend_Controller_Front::getInstance(); $front->registerPlugin(new Plugins_Stats()); if (APPLICATION_ENV == 'production') { $front->registerPlugin(new Plugins_Cache()); } } Zend_View_Helper_PaginationControl::setDefaultViewPartial('_partials/controls.phtml'); parent::run(); }
function connect($name, $db_type, $params) { global $g_db; //try to connect one of connection parameter that works.. $exceptions = array(); foreach ($params as $param) { try { $db = Zend_Db::factory($db_type, $param); $db->setFetchMode(Zend_Db::FETCH_OBJ); $db->getConnection(); //profile db via firebug if (config()->debug) { $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $db->setProfiler($profiler); } //slog("success $name"); $g_db[$name] = $db; return; } catch (Zend_Db_Adapter_Exception $e) { // perhaps a failed login credential, or perhaps the RDBMS is not running wlog("Couldn't connect to {$name} (trying another connection - if available):: " . $e->getMessage()); $exceptions[] = $e; } catch (Zend_Exception $e) { // perhaps factory() failed to load the specified Adapter class wlog("Couldn't connect to {$name} (trying another connection - if available):: " . $e->getMessage()); $exceptions[] = $e; } } $msg = ""; foreach ($exceptions as $e) { $msg .= $e->getMessage() . "\n"; } throw new Exception("Failed to connect to {$name}"); }
/** * Create a Zend_Db_Adapter_Abstract * * @param array $options * @return Zend_Db_Adapter_Abstract */ public static function factory($options) { $adapter = self::_getZendAdapterName($options[WeFlex_Db::ADAPTER]); /** * $TODO check the following validate */ $database = $options[WeFlex_Db::DATABASE]; $username = $options[WeFlex_Db::USER]; $password = $options[WeFlex_Db::PWD]; $host = $options[WeFlex_Db::HOST]; /** * @todo if the adapter is exsit , we could not create it , and get it from registry */ $zendAdapter = Zend_Db::factory($adapter, array('host' => $host, 'username' => $username, 'password' => $password, 'dbname' => $database)); /** * hack for debugger; */ if (WeFlex_Application::GetInstance()->config->db->usefirephp) { $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $zendAdapter->setProfiler($profiler); } $zendAdapter->query("SET NAMES 'utf8'"); return $zendAdapter; }
/** * Initialize db profiling to firebug. Disabled on production. */ protected function _initProfiling() { $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(APPLICATION_ENV != 'production'); $db = $this->getResource('db'); $db->setProfiler($profiler); return $profiler; }
public function _initProfiler() { if ($this->getEnvironment() == 'development') { $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $db = Keplin_Model_Mapper_Abstract::getDefaultDb(); $db->setProfiler($profiler); } }
public function controllerDrivenDB($request) { $controller = $request->getControllerName(); $config = Zend_Registry::get('config'); if (isset($config['resources']['db'][$controller])) { $dbs = $config['resources']['db'][$controller]; if (!isset($dbs[0])) { $dbs = array($dbs); } $dbs = $config['resources']['db'][$controller]; $count = sizeof($dbs); for ($i = 0; $i < $count; $i++) { $connect = true; try { $db = Zend_Db::factory($dbs[$i]['adapter'], $dbs[$i]['params']); $db->getConnection(); } catch (Zend_Db_Adapter_Exception $e) { $connect = false; } catch (Zend_Exception $e) { $connect = false; } if ($connect == true) { Zend_Registry::set('db-prefix', $dbs[$i]['prefix']); break; } } } else { $dbs = $config['resources']['db']; if (!isset($dbs[0])) { $dbs = array($dbs); } $count = sizeof($dbs); for ($i = 0; $i < $count; $i++) { $connect = true; try { $db = Zend_Db::factory($dbs[$i]['adapter'], $dbs[$i]['params']); $db->getConnection(); } catch (Zend_Db_Adapter_Exception $e) { $connect = false; } catch (Zend_Exception $e) { $connect = false; } if ($connect == true) { Zend_Registry::set('db-prefix', $dbs[$i]['prefix']); break; } } } if ($config['evil']['db']['profiling']) { $profiler = new Zend_Db_Profiler_Firebug('DB Queries'); $profiler->setEnabled(true); $db->setProfiler($profiler); } Zend_Registry::set('db', $db); Zend_Db_Table_Abstract::setDefaultAdapter($db); }
/** * Setup the database profiling */ protected function _initDbProfiler() { $this->_logger->info('Bootstrap ' . __METHOD__); if ('production' !== $this->getEnvironment()) { $this->bootstrap('db'); $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $this->getPluginResource('db')->getDbAdapter()->setProfiler($profiler); } }
protected function _initMysql() { $this->bootstrap('db'); switch (APPLICATION_ENV) { case 'development': // this allows you to profile your queries through the firebug console $profiler = new Zend_Db_Profiler_Firebug('System Queries'); $profiler->setEnabled(true); $this->getPluginResource('db')->getDbAdapter()->setProfiler($profiler); break; case 'production': // if you use meta caching in production, which you should :) // Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_cache); break; } }
/** * Starts a query. * * @param string $queryText * @param integer $queryType * @return integer|null */ public function queryStart($queryText, $queryType = null) { $result = parent::queryStart($queryText, $queryType); $backtrace = debug_backtrace(); $trace = array(); foreach ($backtrace as $rec) { if (isset($rec['function'])) { $t['call'] = ''; if (isset($rec['class'])) { $t['call'] .= $rec['class'] . $rec['type'] . $rec['function']; } else { $t['call'] .= $rec['function']; } $t['call'] .= '('; if (sizeof($rec['args'])) { foreach ($rec['args'] as $arg) { if (is_object($arg)) { $t['call'] .= get_class($arg); } else { $arg = str_replace("\n", ' ', (string) $arg); $t['call'] .= '"' . (strlen($arg) <= 30 ? $arg : substr($arg, 0, 25) . '[...]') . '"'; } $t['call'] .= ', '; } $t['call'] = substr($t['call'], 0, -2); } $t['call'] .= ")"; } $t['file'] = @$rec['file'] . ':' . @$rec['line']; $trace[] = $t; } $this->getLastQueryProfile()->bindParam('trace', $trace); return $result; }
public static function start($config, $db) { self::$_config = $config; if (self::$_config['Zend_Db_Profiler_Firebug'] == false) { return; } $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $db->setProfiler($profiler); $request = new Zend_Controller_Request_Http(); self::$_response = new Zend_Controller_Response_Http(); self::$_channel = Zend_Wildfire_Channel_HttpHeaders::getInstance(); self::$_channel->setRequest($request); self::$_channel->setResponse(self::$_response); ob_start(); }
public function init() { $bootstrap = $this->getBootstrap(); try { $bootstrap->bootstrap('db'); } catch (Zend_Application_Bootstrap_Exception $e) { return null; } $db = $bootstrap->db; if ($db !== null) { $profiler = new Zend_Db_Profiler_Firebug('Queries'); $profiler->setEnabled(true); // Attach the profiler to your db adapter $db->setProfiler($profiler); } return $db; }
/** * Enable FirePHP console in not production mode * * @return void */ protected function _initFirebug() { if ('production' === APPLICATION_ENV) { return false; } // bootstrap DB if (!$this->hasResource('db')) { $this->bootstrap('db'); } // init db profiler for firebug if (($db = Zend_Db_Table::getDefaultAdapter()) instanceof Zend_Db_Adapter_Abstract) { $profiler = new Zend_Db_Profiler_Firebug('Db Profiler'); $profiler->setEnabled(true); $db->setProfiler($profiler); } return $profiler; }
public function init() { $this->db = Zend_Registry::get('db'); // turn on profiler $profiler = new Zend_Db_Profiler_Firebug('DB Queries'); $profiler->setEnabled(true); $this->db->setProfiler($profiler); // enable debug Bvb_Grid_Deploy_JqGrid::$debug = true; // enable JQuery - should be part of bootstrap ZendX_JQuery::enableView($this->view); // set url to jqGrid library if (@isset(Zend_Registry::get('config')->site->jqGridUrl)) { Bvb_Grid_Deploy_JqGrid::$defaultJqGridLibPath = Zend_Registry::get('config')->site->jqGridUrl; } $this->_config = new Zend_Config_Ini('./application/grids/grid.ini', 'production'); }
public function bar() { $db = Zend_Db::factory('PDO_SQLITE', array('dbname' => ':memory:')); $profiler = new Zend_Db_Profiler_Firebug('Queries'); $profiler->setEnabled(true); $db->setProfiler($profiler); $db->getConnection()->exec('CREATE TABLE foo ( id INTEGNER NOT NULL, col1 TEXT NOT NULL, col2 TEXT NOT NULL )'); $data = file_get_contents(ZF_APPLICATION_DIRECTORY . '/resources/Test.txt.zip'); $data = new TestObject(); //$db->insert('foo', array('id'=>1,'col1'=>'test text','col2'=>$data)); fb($data); fb('Hello World'); return 'Hello World'; }
public function indexAction() { // action body $this->logger->log("ALERT", Zend_Log::ALERT); $this->logger->log("Debug MSG ", Zend_Log::DEBUG); $this->logger->log("info MSG ", Zend_Log::INFO); $this->logger->log("Crit MSG ", Zend_Log::CRIT); $this->logger->log("notice MSG ", Zend_Log::NOTICE); $this->logger->log($this->getRequest(), Zend_Log::INFO); $this->logger->log($this->db, Zend_Log::INFO); $profiler = new Zend_Db_Profiler_Firebug("GET NOTCIE ITS PROFILER TITLE "); $profiler->setEnabled(true); $this->db->setprofiler($profiler); $sql = "SELECT * FROM countries where countryid = ? "; $result = array(); for ($i = 0; $i < 10; $i++) { $result = $this->db->fetchAll($sql, $i); $this->logger->log($result, Zend_Log::INFO); } }
/** * * @param boolean $enable */ public function setEnabled($enable) { parent::setEnabled($enable); if ($enable) { $this->_message = new TableMessage($this->label); $this->_message->setBuffered(true); $this->_message->setHeader(array('Time', 'Event', 'Parameters', 'Results')); $this->_message->setDestroy(true); Zend_Wildfire_Plugin_FirePhp::getInstance()->send($this->_message); } }
public function _initRegistries() { $this->bootstrap('multidb'); $db = $this->getPluginResource('multidb')->getDb('db'); Zend_Db_Table::setDefaultAdapter($db); //$multidb = $this->getPluginResource('multidb'); Zend_Registry::set('multidb', $db); if ('local' == APPLICATION_ENV) { $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $db->setProfiler($profiler); } Zend_Registry::set('mail', $this->getOption('mail')); Zend_Registry::set('push', $this->getOption('push')); $this->bootstrap('cachemanager'); $cache = $this->getResource('cachemanager')->getCache('file'); Zend_Registry::set('cache', $cache); // $this->_executeResource('log'); // $log = $this->getResource('log'); // Zend_Registry::set('log', $log); }
public function __construct($application) { parent::__construct($application); // get view resources $this->bootstrap('layout'); $layout = $this->getResource('layout'); $this->_view = $layout->getView(); // add view script path $this->_view->setScriptPath(APPLICATION_PATH . '/views/layout/'); // add custom view helpers paths $this->_view->addHelperPath(APPLICATION_PATH . '/views/helpers/'); // setup database for boostrap use $db = $this->getPluginResource('db')->getDbAdapter(); // Firebug DB Profiler if (isset($_GET['profiler']) && $_GET['profiler'] == 'firebug') { $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $db->setProfiler($profiler); } // Force the initial connection to handle error relating to caching etc. try { $db->getConnection(); } catch (Zend_Exception $e) { echo 'ERROR: Cannot connect to database.<br />'; echo $e->getMessage(); die; } Zend_Db_Table::setDefaultAdapter($db); // Set default storage adapter Zend_Registry::set('storage_adapter', 'Application_Model_StorageFilesystem'); // Strip magic quotes if enabled if (get_magic_quotes_gpc()) { function magicQuotes_awStripslashes(&$value, $key) { $value = stripslashes($value); } $gpc = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); array_walk_recursive($gpc, 'magicQuotes_awStripslashes'); } }
public function indexAction() { $this->logger->alert('Alert '); $this->logger->log('Log !', Zend_Log::ERR); $this->logger->err('Error !'); $this->logger->info('Information '); $this->logger->log("Emergency !", Zend_Log::EMERG); $this->logger->log('Warning !', Zend_Log::WARN); $this->logger->log('Debug !', Zend_log::DEBUG); $this->logger->log('critical !', Zend_log::CRIT); $this->logger->log('NOTICE !', Zend_log::NOTICE); $this->logger->log($this->getRequest(), Zend_log::DEBUG); $this->logger->log($this->db, Zend_log::DEBUG); $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); // Attach the profiler to your db adapter $this->db->setProfiler($profiler); $sql = 'SELECT * FROM countries WHERE countryid = ?'; for ($i = 0; $i < 10; $i++) { $result = $this->db->fetchAll($sql, $i); $this->logger->log($result, Zend_log::INFO); } }
Zend_Loader::registerAutoload(); } // ** Get the front controller ** // The Zend_Front_Controller class implements the Singleton pattern, which is a design pattern used to ensure // there is only one instance of Zend_Front_Controller created on each request. $frontController = Zend_Controller_Front::getInstance(); // Point the front controller to your action controller directory. $frontController->setControllerDirectory(APPLICATION_PATH . '/controllers'); // Set up Layout Zend_Layout::startMvc(APPLICATION_PATH . '/views/layouts'); // Set default doctype $view = Zend_Layout::getMvcInstance()->getView(); $view->doctype('XHTML1_STRICT'); $view->headLink()->appendStylesheet('/style/default_layout.css'); $view->addHelperPath(APPLICATION_PATH . '/views/helpers', 'Tg_View_Helper'); //remove $view from global unset($view); // ** Load and register Basic Configuration File ** $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/tablegeeks.xml'); Zend_Registry::set('config', $config); // ** Initialize Logging $log = new Zend_Log(new Zend_Log_Writer_Firebug()); Zend_Registry::set('log', $log); // ** Load and register db access $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $db = Zend_Db::factory($config->db->connection); $profiler->setEnabled($config->db->profiler->enabled); $db->setProfiler($profiler); Zend_Registry::set('db', $db); Zend_Db_Table_Abstract::setDefaultAdapter($db); $frontController->throwExceptions(true);
/** * Intercept the query end and log the profiling data. * * @param integer $queryId * @throws Zend_Db_Profiler_Exception * @return void */ public function queryEnd($queryId) { parent::queryEnd($queryId); if (!$this->getEnabled()) { return; } $this->_message->setDestroy(false); $profile = $this->getQueryProfile($queryId); $this->_totalElapsedTime += $profile->getElapsedSecs(); $this->_message->addRow(array((string) round($profile->getElapsedSecs(), 5), $profile->getQuery(), ($params = $profile->getQueryParams()) ? $params : null, $this->getXdebugStack())); $this->updateMessageLabel(); }
/** * Firebug activation */ private function _activateFirebug() { $oProfiler = new Zend_Db_Profiler_Firebug('DB Queries'); $oProfiler->setEnabled(true); $this->oDb->setProfiler($oProfiler); }
protected function _initDbProfiler() { switch (strtolower(APPLICATION_ENV)) { case 'production': //Not considered yet. break; case 'staging': //Not considered yet. break; case 'testing': //Not considered yet. break; case 'development': $profiler = new Zend_Db_Profiler_Firebug('DB Queries : ' . ucfirst(strtolower(APPLICATION_ENV))); $profiler->setEnabled(true); $db = $this->bootstrapDb()->getResource('db'); $db->setProfiler($profiler); break; default: throw new Zend_Exception('Unknown <b>Application Environment</b> to create db profiler in bootstrap.', Zend_Log::WARN); } }
protected function profiler() { $config = $this->getApplication()->getOptions(); if ($config['env_type'] != 'production' and $config['debug']['profiler']) { $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $db = $this->getResource('multidb')->getDb('main'); $db->setProfiler($profiler); } if ($config['env_type'] != 'production' and $config['debug']['firephplogger']) { $writer = new Zend_Log_Writer_Firebug(); $logger = new Zend_Log($writer); Zend_Registry::set('FirePHPLogger', $logger); } }
/** * Enabling profiler * * @return void */ public static function enableProfiler() { // Enabling Profiler for firebug if (Fox::isProfilerEnabled()) { $profiler = new Zend_Db_Profiler_Firebug('Zendfox DB System Queries'); $profiler->setEnabled(TRUE); // Attach the profiler to your db adapter self::$dbAdapter->setProfiler($profiler); } }
/** * init database */ protected function _initDatabase() { try { // init config $this->bootstrap('config'); // init cache $this->bootstrap('cache'); // get config $config = Knowledgeroot_Registry::get('config'); // get cache $cache = Knowledgeroot_Registry::get('cache'); // make database connect $db = Zend_Db::factory($config->database); // set default adapter Zend_Db_Table_Abstract::setDefaultAdapter($db); // set cache for metadata Zend_Db_Table_Abstract::setDefaultMetadataCache($cache); // use profiler? if ($config->database->profiler) { // init firebug profiler $profiler = new Zend_Db_Profiler_Firebug('All Database Queries:'); // enable it $profiler->setEnabled(true); // attach profiler to db adapter $db->setProfiler($profiler); } // save db handle in registry Knowledgeroot_Registry::set('db', $db); return $db; } catch (Zend_Exception $e) { echo $e->getMessage(); die('no database connection'); } }
switch ($_GET['Example']) { case 'WithController': $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $db = Zend_Db::factory('PDO_SQLITE', array('dbname' => ':memory:')); $db->setProfiler($profiler); Zend_Registry::set('db', $db); $controller = Zend_Controller_Front::getInstance(); $controller->setParam('useDefaultControllerAlways', true); $controller->setParam('noViewRenderer', true); $controller->setControllerDirectory(dirname(dirname(dirname(dirname(__FILE__)))) . '/application/controllers/Boot/Zend-Db-Profiler-Firebug'); $controller->dispatch(); print 'Test Doc Example with Controller'; break; case 'WithoutController': $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $profiler->setEnabled(true); $db = Zend_Db::factory('PDO_SQLITE', array('dbname' => ':memory:')); $db->setProfiler($profiler); $request = new Zend_Controller_Request_Http(); $response = new Zend_Controller_Response_Http(); $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance(); $channel->setRequest($request); $channel->setResponse($response); $db->getConnection()->exec('CREATE TABLE foo ( id INTEGNER NOT NULL, col1 VARCHAR(10) NOT NULL )'); $db->insert('foo', array('id' => 1, 'col1' => 'original')); $channel->flush(); $response->sendHeaders();
/** * Initialize database * * @return My_Plugin_Initialize */ public function initDb() { $config = $this->config->db; $cache = $this->_getCache($config->cache); $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); $db = Zend_Db::factory($config->cxn); $profiler->setEnabled($config->profiler->enabled); $db->setProfiler($profiler); Zend_Db_Table_Abstract::setDefaultAdapter($db); Zend_Db_Table_Abstract::setDefaultMetadataCache($cache); return $this; }