本文整理汇总了PHP中DbSimple_Generic::parseDSN方法的典型用法代码示例。如果您正苦于以下问题:PHP DbSimple_Generic::parseDSN方法的具体用法?PHP DbSimple_Generic::parseDSN怎么用?PHP DbSimple_Generic::parseDSN使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbSimple_Generic
的用法示例。
在下文中一共展示了DbSimple_Generic::parseDSN方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ucfirst
/**
* DbSimple_Generic connect(mixed $dsn)
*
* Universal static function to connect ANY database using DSN syntax.
* Choose database driver according to DSN. Return new instance
* of this driver.
*/
function &connect($dsn)
{
// Load database driver and create its instance.
$parsed = DbSimple_Generic::parseDSN($dsn);
if (!$parsed) {
$dummy = null;
return $dummy;
}
$class = 'DbSimple_' . ucfirst($parsed['scheme']);
if (!class_exists($class)) {
$file = str_replace('_', '/', $class) . ".php";
// Try to load library file from standard include_path.
if ($f = @fopen($file, "r", true)) {
fclose($f);
require_once $file;
} else {
// Wrong include_path; try to load from current directory.
$base = basename($file);
$dir = dirname(__FILE__);
if (@is_file($path = "{$dir}/{$base}")) {
require_once $path;
} else {
trigger_error("Error loading database driver: no file {$file} in include_path; no file {$base} in {$dir}", E_USER_ERROR);
return null;
}
}
}
$object =& new $class($parsed);
if (isset($parsed['ident_prefix'])) {
$object->setIdentPrefix($parsed['ident_prefix']);
}
return $object;
}
示例2: DbSimple_Mysql
/**
* constructor(string $dsn)
* Connect to MySQL.
*/
function DbSimple_Mysql($dsn)
{
$this->dsn = DbSimple_Generic::parseDSN($dsn);
if (!is_callable('mysql_connect')) {
return $this->_setLastError("-1", "MySQL extension is not loaded", "mysql_connect");
}
}
示例3: DbSimple_Ibase
/**
* constructor(string $dsn)
* Connect to Interbase/Firebird.
*/
function DbSimple_Ibase($dsn)
{
$p = DbSimple_Generic::parseDSN($dsn);
if (!is_callable('ibase_connect')) {
return $this->_setLastError("-1", "Interbase/Firebird extension is not loaded", "ibase_connect");
}
$ok = $this->link = ibase_connect($p['host'] . (empty($p['port']) ? "" : ":" . $p['port']) . ':' . preg_replace('{^/}s', '', $p['path']), $p['user'], $p['pass'], isset($p['CHARSET']) ? $p['CHARSET'] : 'win1251', isset($p['BUFFERS']) ? $p['BUFFERS'] : 0, isset($p['DIALECT']) ? $p['DIALECT'] : 3, isset($p['ROLE']) ? $p['ROLE'] : '');
$this->_resetLastError();
if (!$ok) {
return $this->_setDbError('ibase_connect()');
}
}
示例4: DbSimple_Postgresql
/**
* constructor(string $dsn)
* Connect to PostgresSQL.
*/
function DbSimple_Postgresql($dsn)
{
$p = DbSimple_Generic::parseDSN($dsn);
if (!is_callable('pg_connect')) {
return $this->_setLastError("-1", "PostgreSQL extension is not loaded", "pg_connect");
}
$ok = $this->link = @pg_connect($t = (!empty($p['host']) ? 'host=' . $p['host'] . ' ' : '') . (!empty($p['port']) ? 'port=' . $p['port'] . ' ' : '') . 'dbname=' . preg_replace('{^/}s', '', $p['path']) . ' ' . (!empty($p['user']) ? 'user=' . $p['user'] . ' ' : '') . (!empty($p['pass']) ? 'password=' . $p['pass'] . ' ' : ''));
$this->_resetLastError();
if (!$ok) {
return $this->_setDbError('pg_connect()');
}
}
示例5: DbSimple_Postgresql
/**
* constructor(string $dsn)
* Connect to PostgresSQL.
*/
function DbSimple_Postgresql($dsn)
{
$p = DbSimple_Generic::parseDSN($dsn);
if (!is_callable('pg_connect')) {
return $this->_setLastError("-1", "PostgreSQL extension is not loaded", "pg_connect");
}
// Prepare+execute works only in PHP 5.1+.
$this->DbSimple_Postgresql_USE_NATIVE_PHOLDERS = function_exists('pg_prepare');
$ok = $this->link = @pg_connect($t = (!empty($p['host']) ? 'host=' . $p['host'] . ' ' : '') . (!empty($p['port']) ? 'port=' . $p['port'] . ' ' : '') . 'dbname=' . preg_replace('{^/}s', '', $p['path']) . ' ' . (!empty($p['user']) ? 'user=' . $p['user'] . ' ' : '') . (!empty($p['pass']) ? 'password=' . $p['pass'] . ' ' : ''));
$this->_resetLastError();
if (!$ok) {
return $this->_setDbError('pg_connect()');
}
}
示例6: ucfirst
function &connect($dsn)
{
$parsed = DbSimple_Generic::parseDSN($dsn);
if (!$parsed) {
$dummy = null;
return $dummy;
}
$class = 'DbSimple_' . ucfirst($parsed['scheme']);
if (!class_exists($class)) {
$file = str_replace('_', '/', $class) . ".php";
if ($f = @fopen($file, "r", true)) {
fclose($f);
require_once $file;
} else {
$base = basename($file);
$dir = dirname(__FILE__);
if (@is_file($path = "{$dir}/{$base}")) {
require_once $path;
} else {
trigger_error("Error loading database driver: no file {$file} in include_path; no file {$base} in {$dir}", E_USER_ERROR);
return null;
}
}
}
$object =& new $class($parsed);
if (isset($parsed['ident_prefix'])) {
$object->setIdentPrefix($parsed['ident_prefix']);
}
$object->setCachePrefix(md5(serialize($parsed['dsn'])));
if (@fopen('Cache/Lite.php', 'r', true)) {
$tmp_dirs = array(ini_get('session.save_path'), getenv("TEMP"), getenv("TMP"), getenv("TMPDIR"), '/tmp');
foreach ($tmp_dirs as $dir) {
if (!$dir) {
continue;
}
$fp = @fopen($testFile = $dir . '/DbSimple_' . md5(getmypid() . microtime()), 'w');
if ($fp) {
fclose($fp);
unlink($testFile);
require_once 'Cache' . '/Lite.php';
// "." -> no phpEclipse notice
$t =& new Cache_Lite(array('cacheDir' => $dir . '/', 'lifeTime' => null, 'automaticSerialization' => true));
$object->_cacher =& $t;
break;
}
}
}
return $object;
}
示例7: DbSimple_Pmysql
function DbSimple_Pmysql($dsn)
{
$p = DbSimple_Generic::parseDSN($dsn);
if (!is_callable('mysql_pconnect')) {
return $this->_setLastError("-1", "MySQL extension is not loaded", "mysql_pconnect");
}
$ok = $this->link = @mysql_pconnect($p['host'] . (empty($p['port']) ? "" : ":" . $p['port']), $p['user'], $p['pass'], true);
$this->_resetLastError();
if (!$ok) {
return $this->_setDbError('mysql_pconnect()');
}
$ok = @mysql_select_db(preg_replace('{^/}s', '', $p['path']), $this->link);
if (!$ok) {
return $this->_setDbError('mysql_select_db()');
}
}
示例8: DbSimple_Mysql
/**
* constructor(string $dsn)
* Connect to MySQL.
*/
function DbSimple_Mysql($dsn)
{
$p = DbSimple_Generic::parseDSN($dsn);
if (!is_callable('mysql_connect')) {
return $this->_setLastError("-1", "MySQL extension is not loaded", "mysql_connect");
}
$ok = $this->link = @mysql_connect($p['host'] . (empty($p['port']) ? "" : ":" . $p['port']), $p['user'], $p['pass'], true);
$this->_resetLastError();
if (!$ok) {
return $this->_setDbError('mysql_connect()');
}
// aMember custom code
if ($charset = $GLOBALS['config']['db']['mysql']['charset']) {
mysql_set_charset($charset, $this->link);
}
$ok = @mysql_select_db(preg_replace('{^/}s', '', $p['path']), $this->link);
if (!$ok) {
return $this->_setDbError('mysql_select_db()');
}
}
示例9:
/**
* constructor(string $dsn)
* Connect to MySQL.
*/
function DbSimple_Mysql($dsn)
{
$DbSimple = new DbSimple_Generic();
$p = $DbSimple->parseDSN($dsn);
if (!is_callable('mysql_connect')) {
return $this->_setLastError("-1", "MySQL extension is not loaded", "mysql_connect");
}
$ok = $this->link = @mysql_connect($str = $p['host'] . (empty($p['port']) ? "" : ":" . $p['port']), $p['user'], $p['pass'], true);
$this->_resetLastError();
if (!$ok) {
return $this->_setDbError('mysql_connect("' . $str . '", "' . $p['user'] . '")');
}
$ok = @mysql_select_db(preg_replace('{^/}s', '', $p['path']), $this->link);
if (!$ok) {
return $this->_setDbError('mysql_select_db()');
}
if (isset($p["charset"])) {
$this->query('SET NAMES ?', $p["charset"]);
}
}
示例10: DbSimple_Postgresql
/**
* constructor(string $dsn)
* Connect to PostgresSQL.
*/
function DbSimple_Postgresql($dsn)
{
$p = DbSimple_Generic::parseDSN($dsn);
if (!is_callable('pg_connect')) {
return $this->_setLastError("-1", "PostgreSQL extension is not loaded", "pg_connect");
}
// Prepare+execute works only in PHP 5.1+.
$this->DbSimple_Postgresql_USE_NATIVE_PHOLDERS = function_exists('pg_prepare');
$dsnWithoutPass = (!empty($p['host']) ? 'host=' . $p['host'] . ' ' : '') . (!empty($p['port']) ? 'port=' . $p['port'] . ' ' : '') . 'dbname=' . preg_replace('{^/}s', '', $p['path']) . ' ' . (!empty($p['user']) ? 'user=' . $p['user'] : '');
$ok = $this->link = @pg_connect($dsnWithoutPass . " " . (!empty($p['pass']) ? 'password=' . $p['pass'] . ' ' : ''), PGSQL_CONNECT_FORCE_NEW);
// We use PGSQL_CONNECT_FORCE_NEW, because in PHP 5.3 & PHPUnit
// $this->prepareCache may be cleaned, but $this->link is still
// not closed. So the next creation of DbSimple_Postgresql()
// would use exactly the same connection as the previous, but with
// empty $this->prepareCache, and it will generate "prepared statement
// xxx already exists" error each time we execute the same statement
// as in the previous calls.
$this->_resetLastError();
if (!$ok) {
return $this->_setDbError('pg_connect("' . $dsnWithoutPass . '") error');
}
}
示例11: ucfirst
/**
* DbSimple_Generic connect(mixed $dsn)
*
* Universal static function to connect ANY database using DSN syntax.
* Choose database driver according to DSN. Return new instance
* of this driver.
*/
function &connect($dsn)
{
// Load database driver and create its instance.
$parsed = DbSimple_Generic::parseDSN($dsn);
if (!$parsed) {
$dummy = null;
return $dummy;
}
$class = 'DbSimple_' . ucfirst($parsed['scheme']);
$object = new $class($parsed);
if (isset($parsed['ident_prefix'])) {
$object->setIdentPrefix($parsed['ident_prefix']);
}
$object->setCachePrefix(md5(serialize($parsed['dsn'])));
if (@fopen('Cache/Lite.php', 'r', true)) {
$tmp_dirs = array(ini_get('session.save_path'), getenv("TEMP"), getenv("TMP"), getenv("TMPDIR"), '/tmp');
foreach ($tmp_dirs as $dir) {
if (!$dir) {
continue;
}
$fp = @fopen($testFile = $dir . '/DbSimple_' . md5(getmypid() . microtime()), 'w');
if ($fp) {
fclose($fp);
unlink($testFile);
require_once 'Cache' . '/Lite.php';
// "." -> no phpEclipse notice
$t = new Cache_Lite(array('cacheDir' => $dir . '/', 'lifeTime' => null, 'automaticSerialization' => true));
$object->_cacher =& $t;
break;
}
}
}
return $object;
}
示例12: connect
/**
* DbSimple_Generic connect(mixed $dsn)
*
* Universal static function to connect ANY database using DSN syntax.
* Choose database driver according to DSN. Return new instance
* of this driver.
*/
function connect($dsn)
{
// Load database driver and create its instance.
$parsed = DbSimple_Generic::parseDSN($dsn);
if (!$parsed) {
$dummy = null;
return $dummy;
}
$class = 'DbSimple_' . ucfirst($parsed['scheme']);
if (!class_exists($class)) {
$file = dirname(__FILE__) . '/' . ucfirst($parsed['scheme']) . ".php";
if (is_file($file)) {
require_once $file;
} else {
trigger_error("Error loading database driver: no file {$file}", E_USER_ERROR);
return null;
}
}
$object = new $class($parsed);
if (isset($parsed['ident_prefix'])) {
$object->setIdentPrefix($parsed['ident_prefix']);
}
$object->setCachePrefix(md5(serialize($parsed['dsn'])));
return $object;
}
示例13: parseDSN
/**
* Разбирает строку DSN в массив параметров подключения к базе
*
* @param string $dsn строка DSN для разбора
* @return array Параметры коннекта
*/
protected function parseDSN($dsn)
{
return DbSimple_Generic::parseDSN($dsn);
}