예제 #1
0
파일: Base.php 프로젝트: Webowiec/zendnote
 /**
  * Wykonuje wiele zapytań SQL'owych.
  *
  * @param array $aSql
  */
 protected function _execScripts(array $aSql)
 {
     $oConnection = $this->_oDBAdapter->getConnection();
     $bBug = false;
     foreach ($aSql as $sSql) {
         try {
             $oConnection->exec($sSql);
         } catch (Exception $e) {
             switch ($this->_oConfig->db->adapter) {
                 case 'PDO_PGSQL':
                     if (!stristr($e->getMessage(), '42P07')) {
                         throw new Exception($e->getMessage());
                         $bBug = true;
                     }
                     break;
                 default:
                     throw new Exception($e->getMessage());
                     $bBug = true;
                     break;
             }
         }
     }
     if ($bBug) {
         throw new Exception("błąd");
     }
 }
예제 #2
0
파일: TestSetup.php 프로젝트: hjr3/zf2
 /**
  * Open a new database connection
  */
 protected function _setUpAdapter()
 {
     $this->_db = \Zend\DB\DB::factory($this->getDriver(), $this->_util->getParams());
     try {
         $conn = $this->_db->getConnection();
     } catch (\Zend\Exception $e) {
         $this->_db = null;
         $this->assertType('Zend\\DB\\Adapter\\Exception', $e, 'Expecting Zend_Db_Adapter_Exception, got ' . get_class($e));
         $this->markTestSkipped($e->getMessage());
     }
 }
예제 #3
0
 function __construct($config = array())
 {
     // set a Zend_Db_Adapter connection
     if (!empty($config['db'])) {
         // convenience variable
         $db = $config['db'];
         // use an object from the registry?
         if (is_string($db)) {
             $db = Zend::registry($db);
         }
         // make sure it's a Zend_Db_Adapter
         if (!$db instanceof Zend_Db_Adapter_Abstract) {
             throw new Varien_Db_Tree_Exception('db object does not implement Zend_Db_Adapter_Abstract');
         }
         // save the connection
         $this->_db = $db;
         $conn = $this->_db->getConnection();
         if ($conn instanceof PDO) {
             $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
         } elseif ($conn instanceof mysqli) {
             //TODO: ???
         }
     } else {
         throw new Varien_Db_Tree_Exception('db object is not set in config');
     }
     if (!empty($config['table'])) {
         $this->setTable($config['table']);
     }
     if (!empty($config['id'])) {
         $this->setIdField($config['id']);
     } else {
         $this->setIdField('id');
     }
     if (!empty($config['left'])) {
         $this->setLeftField($config['left']);
     } else {
         $this->setLeftField('left_key');
     }
     if (!empty($config['right'])) {
         $this->setRightField($config['right']);
     } else {
         $this->setRightField('right_key');
     }
     if (!empty($config['level'])) {
         $this->setLevelField($config['level']);
     } else {
         $this->setLevelField('level');
     }
     if (!empty($config['pid'])) {
         $this->setPidField($config['pid']);
     } else {
         $this->setPidField('parent_id');
     }
 }
예제 #4
0
파일: TestSetup.php 프로젝트: jsnshrmn/Suma
 /**
  * Open a new database connection
  */
 protected function _setUpAdapter()
 {
     $this->_db = Zend_Db::factory($this->getDriver(), $this->_util->getParams());
     try {
         $conn = $this->_db->getConnection();
     } catch (Zend_Exception $e) {
         $this->_db = null;
         $this->assertTrue($e instanceof Zend_Db_Adapter_Exception, 'Expecting Zend_Db_Adapter_Exception, got ' . get_class($e));
         $this->markTestSkipped($e->getMessage());
     }
 }
예제 #5
0
 /**
  * Drop test table and close connection.
  */
 public function tearDown()
 {
     $this->tearDownMetadata();
     $connection = $this->_db->getConnection();
     $connection = null;
     $this->_db = null;
 }
    protected function _prepareSqliteAdapter()
    {
        $sDbName = AM_Handler_Temp::getInstance()->getFile();
        $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName));
        $sSql = <<<SQL
CREATE TABLE `page_horisontal`
(
       id INTEGER NOT NULL,
       name TEXT,
       resource TEXT,
       PRIMARY KEY(id)
);
SQL;
        $this->_oAdapter->getConnection()->exec($sSql);
        $this->_oSqliteConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName);
        return $this;
    }
    protected function _prepareSqliteAdapter()
    {
        $sDbName = AM_Handler_Temp::getInstance()->getFile();
        $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName));
        $sSql = <<<SQL
CREATE TABLE `page_imposition`
(
       id INTEGER NOT NULL,
       page_id INTEGER NOT NULL,
       is_linked_to INTEGER NOT NULL,
       position_type TEXT NOT NULL,
       PRIMARY KEY(id)
);
SQL;
        $this->_oAdapter->getConnection()->exec($sSql);
        $this->_oConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName);
        return $this;
    }
    protected function _prepareSqliteAdapter()
    {
        $sDbName = AM_Handler_Temp::getInstance()->getFile();
        $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName));
        $sSql = <<<SQL
CREATE TABLE `page`
(
       id INTEGER NOT NULL,
       title TEXT NOT NULL,
       horisontal_page_id INTEGER NOT NULL DEFAULT "-1",
       template INTEGER NOT NULL DEFAULT "-1" ,
       machine_name TEXT,
       color TEXT,
       PRIMARY KEY(id)
)
SQL;
        $this->_oAdapter->getConnection()->exec($sSql);
        $this->_oSqliteConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName);
        return $this;
    }
    protected function _prepareSqliteAdapter()
    {
        $sDbName = AM_Handler_Temp::getInstance()->getFile();
        $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName));
        $sSql = <<<SQL
CREATE TABLE `menu`
(
       id INTEGER NOT NULL,
       title TEXT,
       firstpage_id INTEGER,
       description TEXT,
       thumb_stripe TEXT,
       thumb_summary TEXT,
       color TEXT,
       PRIMARY KEY(id)
);
SQL;
        $this->_oAdapter->getConnection()->exec($sSql);
        $this->_oSqliteConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName);
        return $this;
    }
예제 #10
0
파일: Tree.php 프로젝트: vasiljok/magento2
 /**
  * @param array $config
  * @throws LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function __construct($config = [])
 {
     // set a \Zend_Db_Adapter connection
     if (!empty($config['db'])) {
         // convenience variable
         $connection = $config['db'];
         // use an object from the registry?
         if (is_string($connection)) {
             $connection = \Zend::registry($connection);
         }
         // make sure it's a \Zend_Db_Adapter
         if (!$connection instanceof \Zend_Db_Adapter_Abstract) {
             throw new LocalizedException(new \Magento\Framework\Phrase('db object does not implement \\Zend_Db_Adapter_Abstract'));
         }
         // save the connection
         $this->_db = $connection;
         $conn = $this->_db->getConnection();
         if ($conn instanceof \PDO) {
             $conn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
         }
     } else {
         throw new LocalizedException(new \Magento\Framework\Phrase('db object is not set in config'));
     }
     if (!empty($config['table'])) {
         $this->setTable($config['table']);
     }
     if (!empty($config['id'])) {
         $this->setIdField($config['id']);
     } else {
         $this->setIdField('id');
     }
     if (!empty($config['left'])) {
         $this->setLeftField($config['left']);
     } else {
         $this->setLeftField('left_key');
     }
     if (!empty($config['right'])) {
         $this->setRightField($config['right']);
     } else {
         $this->setRightField('right_key');
     }
     if (!empty($config['level'])) {
         $this->setLevelField($config['level']);
     } else {
         $this->setLevelField('level');
     }
     if (!empty($config['pid'])) {
         $this->setPidField($config['pid']);
     } else {
         $this->setPidField('parent_id');
     }
 }
    protected function _prepareSqliteAdapter()
    {
        $sDbName = AM_Handler_Temp::getInstance()->getFile();
        $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName));
        $sSql = <<<SQL
CREATE TABLE `element`
(
       id INTEGER NOT NULL,
       page_id INTEGER NOT NULL,
       element_type_name TEXT NOT NULL,
       weight INTEGER NOT NULL,
       content_text  BLOB,
       PRIMARY KEY(id)
);

CREATE TABLE `element_data`
(
       id INTEGER NOT NULL,
       element_id INTEGER NOT NULL,
       type TEXT NOT NULL,
       value TEXT NOT NULL,
       position_id  INTEGER,
       PRIMARY KEY(id)
);

CREATE TABLE `element_data_position`
(
       id INTEGER,
       start_x INTEGER,
       start_y INTEGER,
       end_x INTEGER,
       end_y INTEGER,
       PRIMARY KEY(id)
);
SQL;
        $this->_oAdapter->getConnection()->exec($sSql);
        $this->_oConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName);
        return $this;
    }
예제 #12
0
 /**
  * Establish connection and create DB
  *
  * @return Zend_Db_Adapter_Pdo_Sqlite
  * @throws AM_Handler_Export_Sqlite_Exception
  */
 public function getAdapter()
 {
     if (is_null($this->_oAdapter)) {
         $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $this->_getDbFile()));
         $sSchema = @file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Sqlite' . DIRECTORY_SEPARATOR . 'schema.sqlite.sql');
         if (empty($sSchema)) {
             throw new AM_Handler_Export_Sqlite_Exception('Schema file is empty');
         }
         $this->_oAdapter->getConnection()->exec($sSchema);
         AM_Tools_Standard::getInstance()->chmod($this->_getDbFile(), 0666);
     }
     return $this->_oAdapter;
 }
예제 #13
0
 /**
  * Open a new database connection
  */
 protected function _setUpAdapter()
 {
     $params = $this->_util->getParams();
     $params['adapterNamespace'] = 'ZendX_Db_Adapter';
     $this->_db = Zend_Db::factory($this->getDriver(), $params);
     try {
         $conn = $this->_db->getConnection();
     } catch (Zend_Exception $e) {
         $this->_db = null;
         $this->assertType('Zend_Db_Adapter_Exception', $e, 'Expecting Zend_Db_Adapter_Exception, got ' . get_class($e));
         $this->markTestSkipped($e->getMessage());
     }
 }
    protected function _prepareSqliteAdapter()
    {
        $sDbName = AM_Handler_Temp::getInstance()->getFile();
        $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName));
        $sSql = <<<SQL
CREATE TABLE `element`
(
       id INTEGER NOT NULL,
       page_id INTEGER NOT NULL,
       element_type_name TEXT NOT NULL,
       weight INTEGER NOT NULL,
       content_text  BLOB,
       PRIMARY KEY(id)
);

CREATE TABLE `element_data`
(
       id INTEGER NOT NULL,
       element_id INTEGER NOT NULL,
       type TEXT NOT NULL,
       value TEXT NOT NULL,
       position_id  INTEGER,
       PRIMARY KEY(id)
);

CREATE TABLE `game_crossword`
(
       id INTEGER NOT NULL,
       title TEXT,
       grid_width INTEGER,
       grid_height INTEGER,
       PRIMARY KEY(id)
);

CREATE TABLE `game_crossword_word`
(
       id INTEGER NOT NULL,
       game INTEGER NOT NULL,
       answer TEXT NOT NULL,
       question TEXT NOT NULL,
       length INTEGER DEFAULT NULL,
       direction  TEXT NOT NULL,
       start_x INTEGER NOT NULL,
       start_y INTEGER NOT NULL,
       PRIMARY KEY(id)
);
SQL;
        $this->_oAdapter->getConnection()->exec($sSql);
        $this->_oConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName);
        return $this;
    }
예제 #15
0
파일: Db.php 프로젝트: lchen01/STEdwards
 /**
  * Delegate to the database adapter.
  * 
  * @param string $m Method name.
  * @param array $a Method arguments.
  * @return mixed
  */
 public function __call($m, $a)
 {
     if (!method_exists($this->_adapter, $m)) {
         throw new BadMethodCallException("Method named '{$m}' does not exist or is not callable.");
     }
     // Log SQL for certain adapter calls.
     $logFor = array('fetchOne', 'fetchAll', 'prepare', 'query', 'fetchRow', 'fetchAssoc', 'fetchCol', 'fetchPairs');
     if (in_array($m, $logFor)) {
         $this->log($a[0]);
     }
     try {
         return call_user_func_array(array($this->_adapter, $m), $a);
         // Zend_Db_Statement_Mysqli does not consider a connection that returns
         // a "MySQL server has gone away" error to be disconnected. Catch these
         // errors, close the connection, and reconnect, then retry the query.
     } catch (Zend_Db_Statement_Mysqli_Exception $e) {
         if (2006 == $e->getCode()) {
             $this->_adapter->closeConnection();
             $this->_adapter->getConnection();
             return call_user_func_array(array($this->_adapter, $m), $a);
         }
         throw $e;
     }
 }
예제 #16
0
 public function populateTable($tableId)
 {
     $tableName = $this->getTableName($tableId);
     $data = $this->{'_getData' . $tableId}();
     foreach ($data as $row) {
         $sql = 'INSERT INTO ' . $this->_db->quoteIdentifier($tableName, true);
         $cols = array();
         $vals = array();
         foreach ($row as $col => $val) {
             $cols[] = $this->_db->quoteIdentifier($col, true);
             if ($val instanceof Zend_Db_Expr) {
                 $vals[] = $val->__toString();
             } else {
                 $vals[] = $this->_db->quote($val);
             }
         }
         $sql .= ' (' . implode(', ', $cols) . ')';
         $sql .= ' VALUES (' . implode(', ', $vals) . ')';
         $result = $this->_rawQuery($sql);
         if ($result === false) {
             throw new Zend_Db_Exception("Statement failed:\n{$sql}\nError: " . $this->_db->getConnection()->error);
         }
     }
 }
예제 #17
0
 /**
  * Used by _testAdapterOptionCaseFoldingNatural()
  * SQLite needs to do metadata setup,
  * because it uses the in-memory database,
  * so that test suite will override this method.
  */
 protected function _testAdapterOptionCaseFoldingSetup(Zend_Db_Adapter_Abstract $db)
 {
     $db->getConnection();
 }
예제 #18
0
 /**
  * Constructor
  */
 protected function __construct($blnWithDbh = true, Zend_Config_Xml &$sysConfig, Zend_Config_Xml &$zooConfig, Zend_Config_Xml &$config)
 {
     /**
      * set sys config object
      */
     $this->sysConfig = $sysConfig;
     /**
      * set modules config object
      */
     $this->zooConfig = $zooConfig;
     /**
      * set website config object
      */
     $this->config = $config;
     /**
      * initialize Zend_Log
      */
     $this->logger = new Zend_Log();
     /**
      * initialize Zend_Session_Namespace
      */
     $this->objCoreSession = new Zend_Session_Namespace('Core');
     /**
      * create logfile extension for file writer
      */
     $strLogFileExtension = '';
     if ($this->sysConfig->logger->priority > Zend_Log::ERR) {
         if (isset($_SESSION["sesUserName"]) && isset($_SERVER['REMOTE_ADDR'])) {
             $strLogFileExtension = '_' . $_SESSION["sesUserName"] . '_' . $_SERVER['REMOTE_ADDR'];
         } else {
             if (isset($_SERVER['REMOTE_ADDR'])) {
                 $strLogFileExtension = '_' . $_SERVER['REMOTE_ADDR'];
             } else {
                 $strLogFileExtension = '_local';
             }
         }
     }
     /**
      * create log file writer
      */
     $writer = new Zend_Log_Writer_Stream(GLOBAL_ROOT_PATH . $this->sysConfig->logger->path . 'log_' . date('Ymd') . $strLogFileExtension . '.log');
     $this->logger->addWriter($writer);
     /**
      * set log priority
      */
     $filter = new Zend_Log_Filter_Priority((int) $this->sysConfig->logger->priority);
     $this->logger->addFilter($filter);
     /**
      * get language and set translate object
      */
     $this->logger->info('get language from ... ');
     if (isset($_GET['language'])) {
         $this->logger->info('GET');
         $this->strLanguageCode = trim($_GET['language'], '/');
         foreach ($this->config->languages->language->toArray() as $arrLanguage) {
             if (array_key_exists('code', $arrLanguage) && $arrLanguage['code'] == strtolower($this->strLanguageCode)) {
                 $this->intLanguageId = $arrLanguage['id'];
                 break;
             }
         }
         if ($this->intLanguageId == null) {
             if (isset($this->objCoreSession->languageId)) {
                 $this->logger->info('SESSION');
                 $this->intLanguageId = $this->objCoreSession->languageId;
                 $this->strLanguageCode = $this->objCoreSession->languageCode;
             } else {
                 $this->logger->info('DEFAULT');
                 $this->blnIsDefaultLanguage = true;
                 $this->intLanguageId = $this->sysConfig->languages->default->id;
                 $this->strLanguageCode = $this->sysConfig->languages->default->code;
             }
         }
     } else {
         if (isset($_SERVER['REQUEST_URI']) && preg_match('/^\\/[a-zA-Z\\-]{2,5}\\//', $_SERVER['REQUEST_URI'])) {
             $this->logger->info('URI');
             preg_match('/^\\/[a-zA-Z\\-]{2,5}\\//', $_SERVER['REQUEST_URI'], $arrMatches);
             $this->strLanguageCode = trim($arrMatches[0], '/');
             foreach ($this->config->languages->language->toArray() as $arrLanguage) {
                 if (array_key_exists('code', $arrLanguage) && $arrLanguage['code'] == strtolower($this->strLanguageCode)) {
                     $this->intLanguageId = $arrLanguage['id'];
                     break;
                 }
             }
             if ($this->intLanguageId == null) {
                 if (isset($this->objCoreSession->languageId)) {
                     $this->logger->info('SESSION');
                     $this->intLanguageId = $this->objCoreSession->languageId;
                     $this->strLanguageCode = $this->objCoreSession->languageCode;
                 } else {
                     $this->logger->info('DEFAULT');
                     $this->blnIsDefaultLanguage = true;
                     $this->intLanguageId = $this->sysConfig->languages->default->id;
                     $this->strLanguageCode = $this->sysConfig->languages->default->code;
                 }
             }
         } else {
             if (isset($this->objCoreSession->languageId)) {
                 $this->logger->info('SESSION');
                 $this->intLanguageId = $this->objCoreSession->languageId;
                 $this->strLanguageCode = $this->objCoreSession->languageCode;
             } else {
                 $this->logger->info('DEFAULT');
                 $this->blnIsDefaultLanguage = true;
                 $this->intLanguageId = $this->sysConfig->languages->default->id;
                 $this->strLanguageCode = $this->sysConfig->languages->default->code;
             }
         }
     }
     /**
      * set up zoolu translate obj
      */
     $this->intZooluLanguageId = Zend_Auth::getInstance()->hasIdentity() ? Zend_Auth::getInstance()->getIdentity()->languageId : $this->intLanguageId;
     $this->strZooluLanguageCode = Zend_Auth::getInstance()->hasIdentity() ? Zend_Auth::getInstance()->getIdentity()->languageCode : $this->strLanguageCode;
     if (file_exists(GLOBAL_ROOT_PATH . 'application/zoolu/language/zoolu-' . $this->strZooluLanguageCode . '.mo')) {
         $this->translate = new HtmlTranslate('gettext', GLOBAL_ROOT_PATH . 'application/zoolu/language/zoolu-' . $this->strZooluLanguageCode . '.mo');
     } else {
         $this->translate = new HtmlTranslate('gettext', GLOBAL_ROOT_PATH . 'application/zoolu/language/zoolu-' . $this->zooConfig->languages->default->code . '.mo');
     }
     // update session language
     $this->updateSessionLanguage();
     if ($blnWithDbh == true) {
         /**
          * initialize the ZEND DB Connection
          * do lazy connection binding, so db connection will be established on first use with dbh->getConnection()
          */
         try {
             $pdoParams = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true);
             $dbhParameters = array('host' => $this->sysConfig->database->params->host, 'username' => $this->sysConfig->database->params->username, 'password' => $this->sysConfig->database->params->password, 'dbname' => $this->sysConfig->database->params->dbname, 'driver_options' => $pdoParams);
             $this->dbh = Zend_Db::factory($this->sysConfig->database->adapter, $dbhParameters);
             if ($this->sysConfig->logger->priority == Zend_Log::DEBUG) {
                 $this->dbh->getProfiler()->setEnabled(true);
             }
             $this->dbh->getConnection();
             $this->dbh->exec('SET CHARACTER SET ' . $this->sysConfig->encoding->db);
             Zend_Db_Table::setDefaultAdapter($this->dbh);
             /**
              * using a default metadata cache for all table objects
              *
              * set up the cache
              */
             $arrFrontendOptions = array('automatic_serialization' => true);
             /**
              * memcache server configuration
              */
             $arrServer = array('host' => Zend_Cache_Backend_Memcached::DEFAULT_HOST, 'port' => Zend_Cache_Backend_Memcached::DEFAULT_PORT, 'persistent' => Zend_Cache_Backend_Memcached::DEFAULT_PERSISTENT);
             $arrBackendOptions = array('cache_dir' => GLOBAL_ROOT_PATH . $this->sysConfig->path->cache->tables);
             $objCache = Zend_Cache::factory('Core', 'File', $arrFrontendOptions, $arrBackendOptions);
             /**
              * set the cache to be used with all table objects
              */
             Zend_Db_Table_Abstract::setDefaultMetadataCache($objCache);
         } catch (Zend_Db_Adapter_Exception $exc) {
             $this->logger->err($exc);
             header('Location: http://' . $this->sysConfig->hostname);
             die;
         } catch (Zend_Exception $exc) {
             $this->logger->err($exc);
             header('Location: http://' . $this->sysConfig->hostname);
             die;
         }
     }
 }
예제 #19
0
파일: Wrapper.php 프로젝트: sfie/pimcore
 /**
  * @param \Zend_Db_Adapter_Abstract $resource
  */
 protected function closeConnectionResource($resource)
 {
     if ($resource) {
         try {
             $connectionId = null;
             // unfortunately mysqli doesn't throw an exception in the case the connection is lost (issues a warning)
             // and when sending a query to the broken connection (eg. when forking)
             // so we have to handle mysqli and pdo_mysql differently
             if ($resource instanceof \Zend_Db_Adapter_Mysqli) {
                 if ($resource->getConnection()) {
                     $connectionId = $resource->getConnection()->thread_id;
                 }
             } else {
                 if ($resource instanceof \Zend_Db_Adapter_Pdo_Mysql) {
                     $connectionId = $resource->fetchOne("SELECT CONNECTION_ID()");
                 }
             }
             \Logger::debug(get_class($resource) . ": closing MySQL-Server connection with ID: " . $connectionId);
             $resource->closeConnection();
         } catch (\Exception $e) {
             // this is the case when the mysql connection has gone away (eg. when forking using pcntl)
             \Logger::info($e);
         }
     }
 }
예제 #20
0
 /**
  * Used by:
  * - testAdapterOptionCaseFoldingNatural()
  * - testAdapterOptionCaseFoldingUpper()
  * - testAdapterOptionCaseFoldingLower()
  */
 protected function _testAdapterOptionCaseFoldingSetup(Zend_Db_Adapter_Abstract $db)
 {
     $db->getConnection();
     $this->_util->setUp($db);
 }
예제 #21
0
파일: Abstract.php 프로젝트: cwcw/cms
 /**
  * Returns the underlying database connection object or resource.
  * If not presently connected, this initiates the connection.
  *
  * @return object|resource|null
  */
 public function getConnection()
 {
     return $this->_adapter->getConnection();
 }
예제 #22
0
 /**
  * Function to run a SQL script.
  *
  * @param Zend_Db_Adapter_Abstract $db
  * @param string $sqlfile
  * @return true
  * @throws Zend_Exception
  */
 public static function run_sql_from_file($db, $sqlfile)
 {
     $db->getConnection();
     $sql = '';
     $lines = file($sqlfile);
     foreach ($lines as $line) {
         if (trim($line) != '' && substr(trim($line), 0, 2) != '--' && substr($line, 0, 1) != '#') {
             $sql .= $line;
         }
     }
     $queries = explode(';', $sql);
     foreach ($queries as $query) {
         try {
             $db->query($query);
         } catch (Zend_Exception $exception) {
             if (trim($query) != '') {
                 throw new Zend_Exception('Unable to connect.');
             }
         }
     }
     return true;
 }
예제 #23
0
 /**
  * Constructor
  */
 protected function __construct($blnWithDbh = true, Zend_Config_Xml &$sysConfig, Zend_Config_Xml &$modConfig, Zend_Config_Xml &$webConfig)
 {
     /**
      * set sys config object
      */
     $this->sysConfig = $sysConfig;
     /**
      * set modules config object
      */
     $this->modConfig = $modConfig;
     /**
      * set website config object
      */
     $this->webConfig = $webConfig;
     /**
      * initialize Zend_Log
      */
     $this->logger = new Zend_Log();
     /**
      * create logfile extension for file writer
      */
     if (isset($_SESSION["sesUserName"]) && isset($_SERVER['REMOTE_ADDR'])) {
         $strLogFileExtension = $_SESSION["sesUserName"] . '_' . $_SERVER['REMOTE_ADDR'];
     } else {
         if (isset($_SERVER['REMOTE_ADDR'])) {
             $strLogFileExtension = $_SERVER['REMOTE_ADDR'];
         } else {
             $strLogFileExtension = 'local';
         }
     }
     /**
      * create log file writer
      */
     $writer = new Zend_Log_Writer_Stream(GLOBAL_ROOT_PATH . $this->sysConfig->logger->path . 'log_' . date('Ymd') . '_' . $strLogFileExtension . '.log');
     $this->logger->addWriter($writer);
     /**
      * set log priority
      */
     $filter = new Zend_Log_Filter_Priority((int) $this->sysConfig->logger->priority);
     $this->logger->addFilter($filter);
     if ($blnWithDbh == true) {
         /**
          * initialize the ZEND DB Connection
          * do lazy connection binding, so db connection will be established on first use with dbh->getConnection()
          */
         try {
             $pdoParams = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true);
             $dbhParameters = array('host' => $this->sysConfig->database->params->host, 'username' => $this->sysConfig->database->params->username, 'password' => $this->sysConfig->database->params->password, 'dbname' => $this->sysConfig->database->params->dbname, 'driver_options' => $pdoParams);
             $this->dbh = Zend_Db::factory($this->sysConfig->database->adapter, $dbhParameters);
             $this->dbh->getConnection();
             $this->dbh->exec('SET CHARACTER SET ' . $this->sysConfig->encoding->db);
             Zend_Db_Table::setDefaultAdapter($this->dbh);
         } catch (Zend_Db_Adapter_Exception $exc) {
             $this->logger->err($exc);
             header('Location: http://' . $this->sysConfig->hostname);
             die;
         } catch (Zend_Exception $exc) {
             $this->logger->err($exc);
             header('Location: http://' . $this->sysConfig->hostname);
             die;
         }
         //$this->initGuiTexts();
     }
 }