예제 #1
0
 /**
  * Initializes a database connection.
  * It returns the connection, if successful.
  *
  * @param string $db_server
  * @param string $db_name
  * @param string $db_user
  * @param string $db_passwd
  * @param string $db_prefix
  * @param mixed[] $db_options
  *
  * @return resource
  */
 public static function initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options = array())
 {
     // initialize the instance... if not done already!
     if (self::$_db === null) {
         self::$_db = new self();
     }
     if (!empty($db_options['port'])) {
         $db_port = ' port=' . (int) $db_options['port'];
     } else {
         $db_port = '';
     }
     if (!empty($db_options['persist'])) {
         $connection = @pg_pconnect('host=' . $db_server . $db_port . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'');
     } else {
         $connection = @pg_connect('host=' . $db_server . $db_port . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'');
     }
     // Something's wrong, show an error if its fatal (which we assume it is)
     if (!$connection) {
         if (!empty($db_options['non_fatal'])) {
             return null;
         } else {
             display_db_error();
         }
     }
     self::$_db->_connection = $connection;
     return $connection;
 }
예제 #2
0
 public function init()
 {
     $this->_boardurl = 'http://127.0.0.1';
     $this->_db_server = 'localhost';
     $this->_db_type = 'postgresql';
     $this->_db_name = 'hello_world_test';
     $this->_db_user = '******';
     $this->_db_passwd = '';
     $this->_db_prefix = 'elkarte_';
     $connection = Database_PostgreSQL::initiate($this->_db_server, $this->_db_name, $this->_db_user, $this->_db_passwd, $this->_db_prefix);
     $this->_db = Database_PostgreSQL::db();
     $this->load_queries(BOARDDIR . '/install/install_1-0_postgresql.sql');
     $this->prepare();
 }