예제 #1
0
 /**
  * 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
0
 /**
  * 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
0
파일: Ibase.php 프로젝트: space77/mwfv3_sp
 /**
  * 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
0
 /**
  * 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='******'user'] . ' ' : '') . (!empty($p['pass']) ? 'password='******'pass'] . ' ' : ''));
     $this->_resetLastError();
     if (!$ok) {
         return $this->_setDbError('pg_connect()');
     }
 }
예제 #5
0
 /**
  * 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='******'user'] . ' ' : '') . (!empty($p['pass']) ? 'password='******'pass'] . ' ' : ''));
     $this->_resetLastError();
     if (!$ok) {
         return $this->_setDbError('pg_connect()');
     }
 }
 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;
 }
 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
0
 /**
  * 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()');
     }
 }
 /**
  * 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
0
 /**
  * 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='******'user'] : '');
     $ok = $this->link = @pg_connect($dsnWithoutPass . " " . (!empty($p['pass']) ? 'password='******'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');
     }
 }
 /**
  * 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
0
 /**
  * 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
0
파일: Connect.php 프로젝트: saqar/aowow
 /**
  * Разбирает строку DSN в массив параметров подключения к базе
  *
  * @param string $dsn строка DSN для разбора
  * @return array Параметры коннекта
  */
 protected function parseDSN($dsn)
 {
     return DbSimple_Generic::parseDSN($dsn);
 }