public function getCurrentSchemaVersion() { if (empty($this->_module)) { throw new FFR_Exception('Module was empty. A module must be set.'); } $cache = Zend_Controller_Action_HelperBroker::getStaticHelper('Cache')->getManager()->getCache('database'); if (!($version = $cache->load($this->_module . 'Version'))) { // Ensure we have valid connection to the database if (!$this->_db->isConnected()) { $this->_db->getServerVersion(); } $sql = 'SELECT schema_version FROM ' . $this->_schemaVersionTable . ' WHERE schema_module = "' . $this->_module . '"'; $version = null; try { $version = $this->_db->fetchOne($sql); } catch (Zend_Db_Exception $e) { // exception means that the schema version table doesn't exist, so create it $createSql = "CREATE TABLE {$this->_schemaVersionTable} (\n schema_id INT NOT NULL AUTO_INCREMENT,\n schema_version INT NOT NULL,\n schema_module VARCHAR(50),\n PRIMARY KEY (schema_id)\n )"; $this->_db->query($createSql); } // There isn't a version record so lets make one if ($version === null || $version === false) { $insertSql = "INSERT {$this->_schemaVersionTable} SET schema_version = 0," . ' schema_module = "' . $this->_module . '"'; $this->_db->query($insertSql); $version = $this->_db->fetchOne($sql); } $cache->save($version, $this->_module . 'Version', array('schemaVersion')); } return $version; }
public function __construct(Zend_Db_Adapter_Abstract $adapter, $options = array()) { if (!$adapter->isConnected()) { throw new Khcn_Exception('Adapter not connected'); } $this->_adapter = $adapter; if (is_array($options)) { $this->setOptions($options); } }
function getCurrentSchemaVersion() { // Ensure we have valid connection to the database if (!$this->_db->isConnected()) { $this->_db->getServerVersion(); } $schemaVersionTableName = $this->getPrefixedSchemaVersionTableName(); $sql = "SELECT version FROM " . $schemaVersionTableName; try { $version = $this->_db->fetchOne($sql); } catch (Exception $e) { // exception means that the schema version table doesn't exist, so create it $createSql = "CREATE TABLE {$schemaVersionTableName} ( \n version bigint NOT NULL,\n PRIMARY KEY (version)\n )"; $this->_db->query($createSql); $insertSql = "INSERT INTO {$schemaVersionTableName} (version) VALUES (0)"; $this->_db->query($insertSql); $version = $this->_db->fetchOne($sql); } return $version; }
public function openConnection() { if (!self::$dbAdapter) { $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap'); $options = $bootstrap->getOptions(); try { self::$dbAdapter = Zend_Db::factory($options['database']['adapter'], ['host' => $options['database']['params']['host'], 'username' => $options['database']['params']['username'], 'password' => $options['database']['params']['password'], 'dbname' => $options['database']['params']['dbname']]); if (!self::$dbAdapter->isConnected()) { //$this->closeConnection(); //throw new PDOException; } } catch (PDOException $pdo) { die('<div class="big huge"> <span class="icon-warning-sign"></span> <h1>feader reached the maximum limit of parallel users</h1> <h2>We\'re working hard to fix this. Please come back later!</h2> </div>'); } } $this->_db = self::$dbAdapter; $this->_db->query('SET NAMES utf8'); }
/** * Test if a connection is active * * @return boolean */ public function isConnected() { return $this->_adapter->isConnected(); }