本文整理匯總了PHP中erLhcoreClassInstance::setupInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP erLhcoreClassInstance::setupInstance方法的具體用法?PHP erLhcoreClassInstance::setupInstance怎麽用?PHP erLhcoreClassInstance::setupInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類erLhcoreClassInstance
的用法示例。
在下文中一共展示了erLhcoreClassInstance::setupInstance方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: configureObject
public static function configureObject($instance)
{
$cfg = erConfigClassLhConfig::getInstance();
switch ($instance) {
case 'slave':
if ($cfg->getSetting('db', 'use_slaves') === true) {
try {
$dbSlaves = $cfg->getSetting('db', 'db_slaves');
$slaveParams = $dbSlaves[rand(0, count($dbSlaves) - 1)];
$db = ezcDbFactory::create("mysql://{$slaveParams['user']}:{$slaveParams['password']}@{$slaveParams['host']}:{$slaveParams['port']}/{$slaveParams['database']}");
$db->query('SET NAMES utf8');
} catch (Exception $e) {
die('Cannot connect to database.');
}
return $db;
} else {
// Perhaps connection is already done with master?
if (isset(self::$connectionMaster)) {
return self::$connectionMaster;
}
try {
$db = ezcDbFactory::create("mysql://{$cfg->getSetting('db', 'user')}:{$cfg->getSetting('db', 'password')}@{$cfg->getSetting('db', 'host')}:{$cfg->getSetting('db', 'port')}/{$cfg->getSetting('db', 'database')}");
$db->query('SET NAMES utf8');
self::$connectionMaster = $db;
return $db;
} catch (Exception $e) {
die('Cannot connect to database.....');
}
}
break;
case 'dbmongo':
try {
$cfg = erConfigClassLhConfig::getInstance();
$db = ezcDbFactory::create("mongodb://{$cfg->getSetting('dbmongo', 'user')}:{$cfg->getSetting('dbmongo', 'password')}@{$cfg->getSetting('dbmongo', 'host')}:{$cfg->getSetting('dbmongo', 'port')}/{$cfg->getSetting('dbmongo', 'database')}");
return $db;
} catch (Exception $e) {
print_r($e);
die('Cannot connect to mongo database.');
}
break;
case false:
try {
if (isset(self::$connectionMaster)) {
return self::$connectionMaster;
}
// If we do not user slaves and slave request already got connection
$db = ezcDbFactory::create("mysql://{$cfg->getSetting('db', 'user')}:{$cfg->getSetting('db', 'password')}@{$cfg->getSetting('db', 'host')}:{$cfg->getSetting('db', 'port')}/{$cfg->getSetting('db', 'database')}");
$db->query('SET NAMES utf8');
self::$connectionMaster = $db;
erLhcoreClassInstance::setupInstance(self::$connectionMaster);
return $db;
} catch (Exception $e) {
// Are we installed?
if ($cfg->getSetting('site', 'installed') == false) {
header('Location: ' . erLhcoreClassDesign::baseurldirect('site_admin/install/install'));
exit;
}
die('Cannot connect to database. If you are installing application please use /index.php/install/install url. If you keep getting this error please check that application can write to cache folder and cgi.fix_pathinfo = 1');
}
case 'sqlite':
return ezcDbFactory::create('sqlite://:memory:');
}
}