本文整理汇总了PHP中MDB::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP MDB::singleton方法的具体用法?PHP MDB::singleton怎么用?PHP MDB::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDB
的用法示例。
在下文中一共展示了MDB::singleton方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: LiveUser_Admin_Perm_Container_MDB_Simple
/**
* Constructor
*
* @access protected
* @param array full liveuser configuration array
* @return void
* @see LiveUser::factory()
*/
function LiveUser_Admin_Perm_Container_MDB_Simple(&$connectOptions)
{
if (is_array($connectOptions)) {
$function = 'connect';
if (isset($connectOptions['function'])) {
$function = $connectOptions['function'];
unset($connectOptions['function']);
}
foreach ($connectOptions as $key => $value) {
if (isset($this->{$key})) {
$this->{$key} = $value;
}
}
if (isset($connectOptions['connection']) && MDB::isConnection($connectOptions['connection'])) {
$this->dbc =& $connectOptions['connection'];
$this->init_ok = true;
} elseif (isset($connectOptions['dsn'])) {
$this->dsn = $connectOptions['dsn'];
$options = null;
if (isset($connectOptions['options'])) {
$options = $connectOptions['options'];
}
$options['optimize'] = 'portability';
if ($function == 'singleton') {
$this->dbc =& MDB::singleton($connectOptions['dsn'], $options);
} else {
$this->dbc =& MDB::connect($connectOptions['dsn'], $options);
}
if (!MDB::isError($this->dbc)) {
$this->init_ok = true;
}
}
}
}
示例2: init
/**
* Initialize the storage container
*
* @param array Array with the storage configuration
* @return bool true on success, false on failure.
*
* @access public
*/
function init($storageConf)
{
parent::init($storageConf);
if (!MDB::isConnection($this->dbc) && !is_null($this->dsn)) {
$this->options['optimize'] = 'portability';
if ($this->function == 'singleton') {
$dbc =& MDB::singleton($this->dsn, $this->options);
} else {
$dbc =& MDB::connect($this->dsn, $this->options);
}
if (PEAR::isError($dbc)) {
$this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: ' . $dbc->getMessage(), 'debug' => $dbc->getUserInfo()));
return false;
}
$this->dbc =& $dbc;
}
if (!MDB::isConnection($this->dbc)) {
$this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'storage layer configuration missing'));
return false;
}
return true;
}
示例3: LiveUser_Auth_Container_MDB
/**
* Class constructor.
*
* @see LiveUser::factory()
* @access protected
* @param array configuration array
* @return void
*/
function LiveUser_Auth_Container_MDB(&$connectOptions)
{
$this->LiveUser_Auth_Common($connectOptions);
if (is_array($connectOptions)) {
$this->LiveUser_Auth_Common($connectOptions);
if (isset($connectOptions['connection']) && MDB::isConnection($connectOptions['connection'])) {
$this->dbc =& $connectOptions['connection'];
$this->init_ok = true;
} elseif (isset($connectOptions['dsn'])) {
$this->dsn = $connectOptions['dsn'];
$function = null;
if (isset($connectOptions['function'])) {
$function = $connectOptions['function'];
}
$options = null;
if (isset($connectOptions['options'])) {
$options = $connectOptions['options'];
}
$options['optimize'] = 'portability';
if ($function == 'singleton') {
$this->dbc =& MDB::singleton($connectOptions['dsn'], $options);
} else {
$this->dbc =& MDB::connect($connectOptions['dsn'], $options);
}
if (!MDB::isError($this->dbc)) {
$this->init_ok = true;
}
}
}
}
示例4: testSingleton
function testSingleton()
{
$mdb =& MDB::singleton();
$this->assertTrue(MDB::isConnection($mdb));
// should have a different database name set
$mdb =& MDB::singleton($this->dsn, $this->options);
$this->assertTrue($mdb->database != $this->db->database);
}
示例5: init
/**
* Load the storage container
*
* @param mixed &$conf Name of array containing the configuration.
* @param string $containerName name of the container that should be used
* @return boolean true on success or false on failure
*
* @access public
*/
function init(&$conf, $containerName)
{
parent::init($conf, $containerName);
if (is_array($conf['storage'])) {
if (isset($conf['storage']['connection']) && MDB::isConnection($conf['storage']['connection'])) {
$this->dbc =& $conf['storage']['connection'];
} elseif (isset($conf['storage']['dsn'])) {
$this->dsn = $conf['storage']['dsn'];
$function = null;
if (isset($conf['storage']['function'])) {
$function = $conf['storage']['function'];
}
$options = null;
if (isset($conf['storage']['options'])) {
$options = $conf['storage']['options'];
}
$options['optimize'] = 'portability';
if ($function == 'singleton') {
$this->dbc =& MDB::singleton($conf['storage']['dsn'], $options);
} else {
$this->dbc =& MDB::connect($conf['storage']['dsn'], $options);
}
if (PEAR::isError($this->dbc)) {
$this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: ' . $this->dbc->getMessage()));
return false;
}
}
}
return true;
}
示例6: init
/**
*
*
*
* @param array &$storageConf Array with the storage configuration
* @return boolean true on success, false on failure.
*
* @access public
*/
function init($storageConf)
{
if (!parent::init($storageConf)) {
return false;
}
if (array_key_exists('connection', $storageConf) && MDB::isConnection($storageConf['connection'])) {
$this->dbc =& $storageConf['connection'];
} elseif (array_key_exists('dsn', $storageConf)) {
$this->dsn = $storageConf['dsn'];
$function = null;
if (array_key_exists('function', $storageConf)) {
$function = $storageConf['function'];
}
$options = null;
if (array_key_exists('options', $storageConf)) {
$options = $storageConf['options'];
}
$options['optimize'] = 'portability';
if ($function == 'singleton') {
$this->dbc =& MDB::singleton($storageConf['dsn'], $options);
} else {
$this->dbc =& MDB::connect($storageConf['dsn'], $options);
}
if (PEAR::isError($this->dbc)) {
$this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: ' . $this->dbc->getMessage()));
return false;
}
}
return true;
}