/** * Initializes database storage container. * Connects to database or uses existing database connection. * * @param array Storage Configuration * @param array containing the database structure (tables, fields, alias) * @return bool true on success and false on failure * * @access public */ function init(&$storageConf, $structure) { parent::init($storageConf, $structure); if (!is_a($this->dbc, 'pdo') && !is_null($this->dsn)) { $login = $password = $extra = null; if (!empty($this->options)) { if (array_key_exists('username', $this->options)) { $login = $this->options['username']; } if (array_key_exists('password', $this->options)) { $password = $this->options['password']; } if (array_key_exists('attr', $this->options)) { $extra = $this->options['attr']; } } try { $dbc = new PDO($this->dsn, $login, $password, $extra); } catch (PDOException $e) { $this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: ' . $e->getMessage(), 'debug' => $e->getTrace())); return false; } $this->dbc = $dbc; } if (!is_a($this->dbc, 'pdo')) { $this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'storage layer configuration missing')); return false; } return true; }
/** * Initializes database storage container. * Connects to database or uses existing database connection. * * @param array Storage Configuration * @param array containing the database structure (tables, fields, alias) * @return bool true on success and false on failure * * @access public */ function init(&$storageConf, $structure) { parent::init($storageConf, $structure); if (!is_a($this->dbc, 'db_common') && !is_null($this->dsn)) { $this->options['portability'] = DB_PORTABILITY_ALL; $dbc =& DB::connect($this->dsn, $this->options); if (PEAR::isError($dbc)) { $this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: ' . $dbc->getMessage(), 'debug' => $dbc->getUserInfo())); return false; } $this->dbc =& $dbc; } if (!is_a($this->dbc, 'db_common')) { $this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'storage layer configuration missing')); return false; } return true; }
/** * Initializes database storage container. * Connects to database or uses existing database connection. * * @param array Storage Configuration * @param array containing the database structure (tables, fields, alias) * @return bool true on success and false on failure * * @access public */ function init(&$storageConf, $structure) { parent::init($storageConf, $structure); if (!MDB::isConnection($this->dbc) && !is_null($this->dsn)) { $this->options['optimize'] = 'portability'; if ($this->function == 'singleton') { $dbc =& MDB::singleton($this->dsn, $this->options); } else { $dbc =& MDB::connect($this->dsn, $this->options); } if (PEAR::isError($dbc)) { $this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: ' . $dbc->getMessage(), 'debug' => $dbc->getUserInfo())); return false; } $this->dbc =& $dbc; } if (!MDB::isConnection($this->dbc)) { $this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'storage layer configuration missing')); return false; } return true; }