示例#1
0
 /**
  * Create ZFDebug_Controller_Plugin_Debug_Plugin_Variables
  *
  * @param Zend_Db_Adapter_Abstract|array $adapters
  * @return void
  */
 public function __construct(array $options = array())
 {
     if (!isset($options['adapter']) || !count($options['adapter'])) {
         if (AbstractTable::getDefaultAdapter()) {
             $this->_db[0] = AbstractTable::getDefaultAdapter();
             $this->_db[0]->getProfiler()->setEnabled(true);
         }
     } else {
         if ($options['adapter'] instanceof AbstractTable) {
             $this->_db[0] = $options['adapter'];
             $this->_db[0]->getProfiler()->setEnabled(true);
         } else {
             foreach ($options['adapter'] as $name => $adapter) {
                 if ($adapter instanceof AbstractTable) {
                     $adapter->getProfiler()->setEnabled(true);
                     $this->_db[$name] = $adapter;
                 }
             }
         }
     }
     if (isset($options['explain'])) {
         $this->_explain = (bool) $options['explain'];
     }
 }
示例#2
0
 /**
  * _setDbAdapter() - set the database adapter to be used for quering
  *
  * @param Zend_Db_Adapter_Abstract 
  * @throws Zend_Auth_Adapter_Exception
  * @return Zend_Auth_Adapter_DbTable
  */
 protected function _setDbAdapter(AbstractDBAdapter $zendDb = null)
 {
     $this->_zendDb = $zendDb;
     /**
      * If no adapter is specified, fetch default database adapter.
      */
     if (null === $this->_zendDb) {
         $this->_zendDb = AbstractTable::getDefaultAdapter();
         if (null === $this->_zendDb) {
             throw new Exception\RuntimeException('Null was provided for the adapter but there is no default' . ' adatper registered with Zend\\Db\\Table to utilize.');
         }
     }
     return $this;
 }
示例#3
0
 /**
  * Test fallback to default database adapter
  *
  * @group ZF-7510
  */
 public function testAuthenticateWithDefaultDbAdapter()
 {
     // preserve default adapter between cases
     $tmp = \Zend\Db\Table\AbstractTable::getDefaultAdapter();
     // make sure that default db adapter exists
     \Zend\Db\Table\AbstractTable::setDefaultAdapter($this->_db);
     // check w/o passing adapter
     $this->_adapter = new Adapter\DbTable();
     $this->_adapter->setTableName('users')->setIdentityColumn('username')->setCredentialColumn('password')->setTableName('users')->setIdentity('my_username')->setCredential('my_password');
     $result = $this->_adapter->authenticate();
     $this->assertTrue($result->isValid());
     // restore adapter
     \Zend\Db\Table\AbstractTable::setDefaultAdapter($tmp);
 }
示例#4
0
 public function testTableSetDefaultAdapterRegistry()
 {
     /**
      * Don't use _getTable() method because it defaults the adapter
      */
     \Zend\Loader::loadClass('\\ZendTest\\Db\\Table\\TestAsset\\TableBugs');
     \Zend\Registry::set('registered_db', $this->_db);
     Table\AbstractTable::setDefaultAdapter('registered_db');
     $db = Table\AbstractTable::getDefaultAdapter();
     $this->assertSame($this->_db, $db);
     $table = new \ZendTest\Db\Table\TestAsset\TableBugs();
     $db = $table->getAdapter();
     $this->assertSame($this->_db, $db);
 }
示例#5
0
 /**
  * Returns the set adapter
  *
  * @return AbstractDBAdapter
  */
 public function getAdapter()
 {
     /**
      * Check for an adapter being defined. If not, fetch the default adapter.
      */
     if ($this->_adapter === null) {
         $this->_adapter = AbstractTable::getDefaultAdapter();
         if (null === $this->_adapter) {
             throw new Exception\RuntimeException('No database adapter present');
         }
     }
     return $this->_adapter;
 }
示例#6
0
    protected function _createTable()
    {
        $sql = "CREATE TABLE subscription ("
             .      "id varchar(32) PRIMARY KEY NOT NULL DEFAULT '', "
             .      "topic_url varchar(255) DEFAULT NULL, "
             .      "hub_url varchar(255) DEFAULT NULL, "
             .      "created_time datetime DEFAULT NULL, "
             .      "lease_seconds bigint(20) DEFAULT NULL, "
             .      "verify_token varchar(255) DEFAULT NULL, "
             .      "secret varchar(255) DEFAULT NULL, "
             .      "expiration_time datetime DEFAULT NULL, "
             .      "subscription_state varchar(12) DEFAULT NULL"
             . ");";

       \Zend\Db\Table\AbstractTable::getDefaultAdapter()->getConnection()->query($sql);
    }
示例#7
0
    /**
     * Run query and returns matches, or null if no matches are found.
     *
     * @param  String $value
     * @return Array when matches are found.
     */
    protected function _query($value)
    {
        /**
         * Check for an adapter being defined. if not, fetch the default adapter.
         */
        if ($this->_adapter === null) {
            $this->_adapter = AbstractTable::getDefaultAdapter();
            if (null === $this->_adapter) {
                throw new Exception\RuntimeException('No database adapter present');
            }
        }

        /**
         * Build select object
         */
        $select = new DBSelect($this->_adapter);
        $select->from($this->_table, array($this->_field), $this->_schema)
               ->where($this->_adapter->quoteIdentifier($this->_field, true).' = ?', $value);
        if ($this->_exclude !== null) {
            if (is_array($this->_exclude)) {
                $select->where($this->_adapter->quoteIdentifier($this->_exclude['field'], true).' != ?', $this->_exclude['value']);
            } else {
                $select->where($this->_exclude);
            }
        }
        $select->limit(1);

        /**
         * Run query
         */
        $result = $this->_adapter->fetchRow($select, array(), Db::FETCH_ASSOC);

        return $result;
    }
示例#8
0
 /**
  * _setDbAdapter() - set the database adapter to be used for quering
  *
  * @param Zend_Db_Adapter_Abstract 
  * @throws Zend_Auth_Adapter_Exception
  * @return Zend_Auth_Adapter_DbTable
  */
 protected function _setDbAdapter(AbstractDBAdapter $zendDb = null)
 {
     $this->_zendDb = $zendDb;
     /**
      * If no adapter is specified, fetch default database adapter.
      */
     if (null === $this->_zendDb) {
         $this->_zendDb = AbstractTable::getDefaultAdapter();
         if (null === $this->_zendDb) {
             throw new Exception('No database adapter present');
         }
     }
     return $this;
 }