Zend_Db_Table_Abstract::setDefaultAdapter PHP Method

setDefaultAdapter() public static method

Sets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.
public static setDefaultAdapter ( mixed $db = null ) : void
$db mixed Either an Adapter object, or a string naming a Registry key
return void
    public static function setDefaultAdapter($db = null)
    {
        self::$_defaultDb = self::_setupAdapter($db);
    }

Usage Example

Example #1
0
 /**
  * @todo expireSessionCookie()
  * @todo rememberMe(xx)
  * @todo forgetMe()
  * @see Zend_Registry::get('session');
  * @return Zend_Session_Namespace
  */
 protected function _initSession()
 {
     $options = $this->getOption('ca_mgr');
     $db = Zend_Db::factory($options['db']['session']['pdo'], $options['db']['session']);
     /**
      * automatically clean up expired session entries from session cache
      * use the modified and lifetime stamps to calculate expire time
      */
     if ($options['db']['session']['autocleanup'] == '1') {
         $stmt = $db->query('delete from front_session where (modified + lifetime * 2) < unix_timestamp()');
         # $stmt->execute();
     }
     //you can either set the Zend_Db_Table default adapter
     //or you can pass the db connection straight to the save handler $config
     // @see lifetimeColumn / lifetime / overrideLifetime, lifetime defaults to php.ini: session.gc_maxlifetime
     Zend_Db_Table_Abstract::setDefaultAdapter($db);
     $config = array('name' => 'front_session', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime');
     //create your Zend_Session_SaveHandler_DbTable and
     //set the save handler for Zend_Session
     Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
     // Zend_Session::rememberMe(7200);
     //start your session!
     Zend_Session::start();
     $session = new Zend_Session_Namespace();
     if (!isset($session->started)) {
         $session->started = time();
     }
     if (!isset($session->authdata)) {
         $session->authdata = array('authed' => false);
     }
     Zend_Registry::set('session', $session);
     return $session;
 }
All Usage Examples Of Zend_Db_Table_Abstract::setDefaultAdapter