本文整理汇总了PHP中Zend_Db_Table_Abstract::setDefaultAdapter方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db_Table_Abstract::setDefaultAdapter方法的具体用法?PHP Zend_Db_Table_Abstract::setDefaultAdapter怎么用?PHP Zend_Db_Table_Abstract::setDefaultAdapter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Db_Table_Abstract
的用法示例。
在下文中一共展示了Zend_Db_Table_Abstract::setDefaultAdapter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initSession
/**
* @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;
}
示例2: _initDB
/**
* Inicializa a conexão com o banco de dados
* Usa o Zend_Cache para o metadata das tabelas
*
* @uses Zend_Cache
*/
protected function _initDB()
{
// Configura a conexão com o BD
$config = new Zend_Config($this->getOptions());
$db = Zend_Db::factory($config->resources->db);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
}
示例3: _initDb
/**
* Store the db adapter in the registry
* and set the default one for the mappers
*
* @return Zend_Db_Adapter_Abstract
*/
protected function _initDb()
{
$db = $this->getPluginResource('db')->getDbAdapter();
Zend_Registry::set('db', $db);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
return $db;
}
示例4: _initDb
protected function _initDb()
{
$config = Zend_Registry::get('config');
$options = $config->mtb->db->params;
$db = Zend_Db::factory('PDO_MYSQL', $options);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
}
示例5: tearDown
/**
* Cleans up the environment after running a test.
*/
protected function tearDown()
{
$this->Feeds = null;
// restore the old default db
Zend_Db_Table_Abstract::setDefaultAdapter($this->oldDefaultDb);
parent::tearDown();
}
示例6: run
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();
}
示例7: setDbAdapter
public static function setDbAdapter()
{
$cnf = Zend_Registry::get('cnf');
$db = Zend_Db::factory($cnf->db);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
Zend_Registry::set('db', $db);
}
示例8: dispatchLoopStartup
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
$auth = Zend_Auth::getInstance();
$result = $auth->getStorage();
$identity = $auth->getIdentity();
$registry = Zend_Registry::getInstance();
$config = Zend_Registry::get('config');
$module = strtolower($this->_request->getModuleName());
$controller = strtolower($this->_request->getControllerName());
$action = strtolower($this->_request->getActionName());
if ($identity && $identity != "") {
$layout = Zend_Layout::getMvcInstance();
$view = $layout->getView();
$view->login = $identity;
$siteInfoNamespace = new Zend_Session_Namespace('siteInfoNamespace');
$id = $siteInfoNamespace->userId;
$view->firstname = $siteInfoNamespace->Firstname;
$username = $siteInfoNamespace->username;
$password = $siteInfoNamespace->password;
$db = new Zend_Db_Adapter_Pdo_Mysql(array('host' => $config->resources->db->params->host, 'username' => $username, 'password' => $password, 'dbname' => $config->resources->db->params->dbname));
Zend_Db_Table_Abstract::setDefaultAdapter($db);
return;
} else {
$siteInfoNamespace = new Zend_Session_Namespace('siteInfoNamespace');
$siteInfoNamespace->requestURL = $this->_request->getParams();
$this->_request->setModuleName('default');
$this->_request->setControllerName('Auth');
$this->_request->setActionName('login');
}
}
示例9: routeShutdown
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$useModule = array('default', 'mice');
if (in_array($request->getModuleName(), $useModule) and $this->getRequest()->getParam('language') != 'scripts') {
Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Registry::get('read'));
} else {
Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Registry::get('write'));
}
if (in_array($request->getModuleName(), $useModule) and $this->getRequest()->getParam('language') != 'scripts') {
$language = $this->getRequest()->getParam('language');
if (empty($language)) {
$language = 'id';
}
// Model
$dictionaryDb = new Model_DbTable_Dictionary();
$languageDb = new Model_DbTable_Language();
// Data
$dictionary = $dictionaryDb->getDictionaryArray($language);
$languageId = $languageDb->getIdByName($language);
try {
// Translator Zend
$translate = new Zend_Translate('array', $dictionary, $language);
// Set registry
Zend_Registry::set('Zend_Translate', $translate);
Zend_Registry::set('language', $language);
Zend_Registry::set('languageId', $languageId['language_id']);
Zend_Registry::set('languageText', $languageId['language_text']);
} catch (Zend_Translate_Exception $zte) {
} catch (Zend_Exception $ze) {
}
}
}
示例10: testAction
public function testAction()
{
$time_start = microtime(true);
$params = array('host' => '127.0.0.1', 'username' => 'root', 'password' => 'root', 'dbname' => 'langithp');
$db = Zend_Db::factory('PDO_MYSQL', $params);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
require_once '/Users/n/Documents/Work/Zend/kutump/test/CatalogAttribute.php';
$tbl = new CatalogAttribute();
$rows = $tbl->fetchAll();
$num = count($rows);
echo "<b><center>Database Output</center></b><br><br>";
$i = 0;
for ($i = 0; $i < $num; $i++) {
//$tmpGuid = mysql_result($result,$i,"guid");
$row = $rows->current();
$tmpGuid = $row->title;
echo '<br>' . $tmpGuid;
echo '<br>' . $i;
$rows->next();
//$i++;
}
$dbh = null;
echo '<br>Total: ' . $i;
$time_end = microtime(true);
$time = $time_end - $time_start;
echo '<br>WAKTU EKSEKUSI: ' . $time;
//die('hiho');
}
示例11: __construct
function __construct()
{
$options = array('host' => 'localhost', 'username' => 'root', 'password' => 'root', 'dbname' => 'zendcastdev');
$this->db = Zend_Db::factory('PDO_MYSQL', $options);
Zend_Db_Table_Abstract::setDefaultAdapter($this->db);
$this->users = new UsersTable();
}
示例12: init_zend_db
/**
* Initizlize Zend DB
*/
function init_zend_db()
{
try {
include APPPATH . 'config' . DIRECTORY_SEPARATOR . 'database.php';
$__dbParams = array('host' => $db[$active_group]['hostname'], 'username' => $db[$active_group]['username'], 'password' => $db[$active_group]['password'], 'dbname' => $db[$active_group]['database'], 'persistent' => $db[$active_group]['pconnect']);
$__db = Zend_Db::factory('PDO_MYSQL', $__dbParams);
include APPPATH . 'config/cache.php';
$feEngine = $config['dbschema_frontend_engine'];
$feOptions = $config['dbschema_frontend'];
$beEngine = $config['dbschema_backend_engine'];
$beOptions = $config['dbschema_backend'];
if (isset($beOptions['cache_dir']) && !file_exists($beOptions['cache_dir'])) {
mkdir($beOptions['cache_dir']);
chmod($beOptions['cache_dir'], 0777);
}
// var_dump($beOptions['cache_dir']);
$cache = Zend_Cache::factory($feEngine, $beEngine, $feOptions, $beOptions);
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
Zend_Db_Table_Abstract::setDefaultAdapter($__db);
Profiler::start($db[$active_group], $__db);
$__db->query('SET NAMES ' . $db['default']['char_set']);
$__db->query('SET SQL_MODE = "NO_UNSIGNED_SUBTRACTION"');
} catch (Exception $e) {
header("HTTP/1.1 500 Internal Server Error (DB)");
echo $e->getMessage();
exit;
}
}
示例13: __construct
public function __construct()
{
//set country
//lookup country from subdomain
// must be format like http://country.site.org
$parts = explode('.', $_SERVER['HTTP_HOST']);
self::$COUNTRY = $parts[0];
require_once 'settings.php';
$countryLoaded = false;
if ($parts[1] == 'trainingdata') {
Settings::$DB_DATABASE = Globals::$DB_TABLE_PREFIX . $parts[0];
self::$COUNTRY = $parts[0];
Settings::$COUNTRY_BASE_URL = 'http://' . $parts[0] . '.' . Globals::$DOMAIN;
$countryLoaded = true;
}
error_reporting(E_ALL);
// PATH_SEPARATOR = ; for windows, : for *nix
$iReturn = ini_set('include_path', Globals::$BASE_PATH . PATH_SEPARATOR . Globals::$BASE_PATH . 'app' . PATH_SEPARATOR . (Globals::$BASE_PATH . 'ZendFramework' . DIRECTORY_SEPARATOR . 'library') . PATH_SEPARATOR . ini_get('include_path'));
require_once 'Zend/Loader.php';
if ($countryLoaded) {
//fixes mysterious configuration issue
require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
require_once 'Zend/Db.php';
//set a default database adaptor
$db = Zend_Db::factory('PDO_MYSQL', array('host' => Settings::$DB_SERVER, 'username' => Settings::$DB_USERNAME, 'password' => Settings::$DB_PWD, 'dbname' => Settings::$DB_DATABASE));
require_once 'Zend/Db/Table/Abstract.php';
Zend_Db_Table_Abstract::setDefaultAdapter($db);
}
}
示例14: _initDb
public function _initDb()
{
$resource = $this->getPluginResource('db');
$options = $resource->getOptions();
$db = new Zend_Db_Adapter_Pdo_Mysql($options["params"]);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
}
示例15: _initSession
/**
* initalize session
*/
protected function _initSession()
{
$resource = $this->getPluginResource('db');
$db = $resource->getDbAdapter();
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$config = array('name' => 'sessions', 'primary' => 'sessionId', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime', 'lifetime' => 60 * 60 * 24 * 14);
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
}