本文整理汇总了PHP中OA_DB::getDsnOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP OA_DB::getDsnOptions方法的具体用法?PHP OA_DB::getDsnOptions怎么用?PHP OA_DB::getDsnOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OA_DB
的用法示例。
在下文中一共展示了OA_DB::getDsnOptions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: singleton
/**
* A method to return a singleton database connection resource.
*
* Example usage:
* $oDbh = OA_DB::singleton();
*
* Warning: In order to work correctly, the singleton method must
* be instantiated statically and by reference, as in the above
* example.
*
* @static
* @param string $dsn Optional database DSN details - connects to the
* database defined by the configuration file otherwise.
* See {@link OA_DB::getDsn()} for format.
*
* @param array $aDriverOptions An optional array of driver options. Currently
* supported options are:
* - For MySQL:
* ['ssl'] = false|true Perform connection over SSL?
* ['ca'] = Name of CA file, if "ssl" true
* ['capath'] = Path to CA file above, is "ssl" true
* ['compress'] = false|true Use client compression?
*
* @return MDB2_Driver_Common An MDB2 connection resource, or PEAR_Error
* on failure to connect.
*/
static function singleton($dsn = null, $aDriverOptions = array())
{
$aConf = $GLOBALS['_MAX']['CONF'];
// Get the driver options, if not set
if (!is_array($aDriverOptions) || is_null($dsn) && empty($aDriverOptions)) {
$aDriverOptions = OA_DB::getDsnOptions();
}
// Get the DSN, if not set
$dsn = is_null($dsn) ? OA_DB::getDsn() : $dsn;
// Check that the parameter is a string, not an array
if (is_array($dsn)) {
return Max::raiseError('Bad argument: DSN should be a string', MAX_ERROR_INVALIDARGS);
}
// A hack to allow for installation on pgsql
// If the configuration hasn't been defined prevent
// loading mysql MDB2 driver.
if (strpos($dsn, '//:@') !== false) {
// Return a silent error
return new PEAR_Error('Bad argument: Empty DSN');
}
// Get the database type in use from the DNS, not from the
// configuration file
$aDSN = MDB2::parseDSN($dsn);
$databaseType = $aDSN['phptype'];
// Is this a MySQL database connection that should happen via SSL?
if (strcasecmp($databaseType, 'mysql') === 0 && @$aDriverOptions['ssl']) {
// Modify the DSN string to include the required CA and CAPATH options
if (!empty($aDriverOptions['ca']) && !empty($aDriverOptions['capath'])) {
$dsn .= "?ca={$aDriverOptions['ca']}&capth={$aDriverOptions['capath']}";
}
}
// Create an MD5 checksum of the DSN
$dsnMd5 = md5($dsn);
// Does this database connection already exist?
if (isset($GLOBALS['_OA']['CONNECTIONS'])) {
$aConnections = array_keys($GLOBALS['_OA']['CONNECTIONS']);
} else {
$aConnections = array();
}
if (!(count($aConnections) > 0) || !in_array($dsnMd5, $aConnections)) {
// Prepare options for a new database connection
$aOptions = array();
// Sequence column name
$aOptions['seqcol_name'] = 'id';
// Set the index name format
$aOptions['idxname_format'] = '%s';
// Use 4 decimal places in DECIMAL nativetypes
$aOptions['decimal_places'] = 4;
// Set the portability options
$aOptions['portability'] = OA_DB_MDB2_DEFAULT_OPTIONS;
// Set the default table type for MySQL, if appropriate
if (strcasecmp($databaseType, 'mysql') === 0) {
if (!empty($aConf['table']['type'])) {
$aOptions['default_table_type'] = $aConf['table']['type'];
// Enable transaction support when using InnoDB tables
if (strcasecmp($aOptions['default_table_type'], 'innodb') === 0) {
// Enable transaction support
$aOptions['use_transactions'] = true;
}
}
} elseif (strcasecmp($databaseType, 'pgsql') === 0) {
$aOptions['quote_identifier'] = true;
}
// Add default charset - custom OpenX
if (defined('OA_DB_MDB2_DEFAULT_CHARSET')) {
$aOptions['default_charset'] = OA_DB_MDB2_DEFAULT_CHARSET;
} else {
$aOptions['default_charset'] = 'utf8';
}
// this will log select queries to a var/sql.log
// currently used for analysis purposes
if (isset($aConf['debug']['logSQL']) && $aConf['debug']['logSQL']) {
$aOptions['log_statements'] = explode('|', $aConf['debug']['logSQL']);
$aOptions['debug'] = true;
//.........这里部分代码省略.........