Example #1
0
 /**
  * Create a singleton of ADODB or ADODBLite;  This driver works for 
  * both.  Just specify the correct directory in 
  * config->db->options->adodbDir.
  * The directory in which adodbDir resides in must be in your
  * include_path.
  *
  * @access public
  * @throws Framework_DB_Exception on failure
  * @return object                 Instance of ADODB[Lite] connected to the DB
  */
 public function singleton()
 {
     if (!is_null(parent::$db) && parent::$db instanceof ADOConnection) {
         return parent::$db;
     }
     // Manually include files, ADODB does not follow naming conventions
     if (empty($this->options->adodbDir)) {
         throw new Framework_DB_Exception('Error: you must set $config->db->options->adodbDir');
     }
     $path = (string) $this->options->adodbDir . DIRECTORY_SEPARATOR;
     if (!(include_once $path . 'adodb-exceptions.inc.php') || !(include_once $path . 'adodb.inc.php')) {
         throw new Framework_DB_Exception('Error: could not include ADODB files');
     }
     // Connect
     try {
         parent::$db = ADONewConnection($this->dsn);
     } catch (Exception $error) {
         throw new Framework_DB_Exception($error->getMessage(), $error->getCode());
     }
     // Fetch Modes
     $fetchModes = array('ADODB_FETCH_DEFAULT' => ADODB_FETCH_DEFAULT, 'ADODB_FETCH_NUM' => ADODB_FETCH_NUM, 'ADODB_FETCH_ASSOC' => ADODB_FETCH_ASSOC, 'ADODB_FETCH_BOTH' => ADODB_FETCH_BOTH);
     $fetchMode = ADODB_FETCH_ASSOC;
     if (isset($this->options->fetchMode) && isset($fetchModes[(string) $this->options->fetchMode])) {
         $fetchMode = $fetchModes[(string) $this->options->fetchMode];
     }
     parent::$db->SetFetchMode($fetchMode);
     return parent::$db;
 }
Example #2
0
 /**
  * Create a singleton of PEAR's DB 
  *
  * @access      public
  * @return      object      Instance of PEAR DB connected to the DB
  * @throws      Framework_DB_Exception
  */
 public function singleton()
 {
     if (!is_null(parent::$db) && parent::$db instanceof MDB2_Driver_Common) {
         return parent::$db;
     }
     parent::$db = MDB2::connect($this->dsn);
     if (PEAR::isError(parent::$db)) {
         throw new Framework_DB_Exception(parent::$db->getMessage(), parent::$db->getCode());
     }
     $fetchMode = MDB2_FETCHMODE_ASSOC;
     if (isset($this->options->fetchMode) && isset(self::$fetchModes[(string) $this->options->fetchMode])) {
         $fetchMode = self::$fetchModes[(string) $this->options->fetchMode];
     }
     parent::$db->setFetchMode($fetchMode);
     return parent::$db;
 }
 public function __construct($id = '')
 {
     parent::$db = self::$db;
     parent::__construct($id);
 }
Example #4
0
 public static function init()
 {
     global $discuz;
     parent::$db = $discuz->db;
 }