89 lines
2.1 KiB
PHP
89 lines
2.1 KiB
PHP
<?php
|
|
|
|
class createCon
|
|
{
|
|
public $host;
|
|
public $user;
|
|
public $pass;
|
|
public $db;
|
|
public $dbSpota;
|
|
public $dbBio;
|
|
public $dbDosen;
|
|
|
|
public $myconn;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->host = getenv('DB_HOST') ?: 'localhost';
|
|
$this->user = getenv('DB_USER') ?: 'spota_informatika';
|
|
$this->pass = getenv('DB_PASSWORD') ?: 'Eud!}ZML3HVO';
|
|
$this->db = getenv('DB_SPOTA') ?: getenv('DB_NAME') ?: 'spota_spotadb';
|
|
$this->dbSpota = getenv('DB_SPOTA') ?: getenv('DB_NAME') ?: 'spota_spotadb';
|
|
$this->dbBio = getenv('DB_BIO') ?: 'enda_daftarmhs';
|
|
$this->dbDosen = getenv('DB_DOSEN') ?: 'enda_dosen';
|
|
}
|
|
|
|
public function connect()
|
|
{
|
|
$con = new PDO('mysql:host='.$this->host.';dbname='.$this->db, $this->user, $this->pass);
|
|
if (!$con) {
|
|
die('Could not connect to database!');
|
|
} else {
|
|
$this->myconn = $con;
|
|
}
|
|
|
|
return $this->myconn;
|
|
}
|
|
|
|
public function close()
|
|
{
|
|
$this->myconn = null;
|
|
}
|
|
|
|
public function connectSpota()
|
|
{
|
|
$con = new PDO('mysql:host='.$this->host.';dbname='.$this->dbSpota, $this->user, $this->pass);
|
|
if (!$con) {
|
|
die('Could not connect to database!');
|
|
} else {
|
|
$this->myconn = $con;
|
|
}
|
|
|
|
return $this->myconn;
|
|
}
|
|
|
|
public function connectDbBio()
|
|
{
|
|
$con = new PDO('mysql:host='.$this->host.';dbname='.$this->dbBio, $this->user, $this->pass);
|
|
if (!$con) {
|
|
die('Could not connect to database!');
|
|
} else {
|
|
$this->myconn = $con;
|
|
}
|
|
|
|
return $this->myconn;
|
|
}
|
|
|
|
public function closeDbBio()
|
|
{
|
|
$this->myconn = null;
|
|
}
|
|
|
|
public function connectDbDosen()
|
|
{
|
|
$con = new PDO('mysql:host='.$this->host.';dbname='.$this->dbDosen, $this->user, $this->pass);
|
|
if (!$con) {
|
|
die('Could not connect to database!');
|
|
} else {
|
|
$this->myconn = $con;
|
|
}
|
|
|
|
return $this->myconn;
|
|
}
|
|
|
|
public function closeDbDosen()
|
|
{
|
|
$this->myconn = null;
|
|
}
|
|
}
|