本文整理汇总了PHP中MDB::setOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP MDB::setOptions方法的具体用法?PHP MDB::setOptions怎么用?PHP MDB::setOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDB
的用法示例。
在下文中一共展示了MDB::setOptions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* Returns a MDB connection with the requested DSN.
* A newnew MDB connection object is only created if no object with the
* reuested DSN exists yet.
*
* IMPORTANT: In order for MDB to work properly it is necessary that
* you make sure that you work with a reference of the original
* object instead of a copy (this is a PHP4 quirk).
*
* For example:
* $mdb =& MDB::sngleton($dsn);
* ^^
* And not:
* $mdb = MDB::singleton($dsn);
* ^^
*
* @param mixed $dsn 'data source name', see the MDB::parseDSN
* method for a description of the dsn format.
* Can also be specified as an array of the
* format returned by MDB::parseDSN.
* @param mixed $options An associative array of option names and
* their values.
* @return mixed a newly created MDB connection object, or a MDB
* error object on error
* @access public
* @see MDB::parseDSN
*/
function &singleton($dsn = NULL, $options = FALSE)
{
if ($dsn) {
$dsninfo = MDB::parseDSN($dsn);
$dsninfo_default = array('phptype' => NULL, 'username' => NULL, 'password' => NULL, 'hostspec' => NULL, 'database' => NULL);
$dsninfo = array_merge($dsninfo_default, $dsninfo);
$keys = array_keys($GLOBALS['_MDB_databases']);
for ($i = 0, $j = count($keys); $i < $j; ++$i) {
$tmp_dsn = $GLOBALS['_MDB_databases'][$keys[$i]]->getDSN('array');
if ($dsninfo['phptype'] == $tmp_dsn['phptype'] && $dsninfo['username'] == $tmp_dsn['username'] && $dsninfo['password'] == $tmp_dsn['password'] && $dsninfo['hostspec'] == $tmp_dsn['hostspec'] && $dsninfo['database'] == $tmp_dsn['database']) {
MDB::setOptions($GLOBALS['_MDB_databases'][$keys[$i]], $options);
return $GLOBALS['_MDB_databases'][$keys[$i]];
}
}
} else {
if (is_array($GLOBALS['_MDB_databases']) && reset($GLOBALS['_MDB_databases'])) {
$db =& $GLOBALS['_MDB_databases'][key($GLOBALS['_MDB_databases'])];
return $db;
}
}
$db =& MDB::connect($dsn, $options);
return $db;
}