本文整理汇总了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:');
}
}