<?php
class ExternalConnection {
private $servernameExternal = "127.0.0.1";
// private $servernameExternal = "209.97.141.66";
private $usernameExternal = CONFIG_DB_USER_EXTERN;
private $passwordExternal = CONFIG_DB_PWD_EXTERN;
private $databaseExternal = CONFIG_DB_NAME_EXTERN;
private $port = CONFIG_DB_PORT;
private $connectionExtern;
function __construct()
{
if($_SERVER['SERVER_NAME']=="unittest"){
$this->servernameExternal = "127.0.0.1";
$this->databaseExternal = "test_db";
$this->usernameExternal = "devuser";
$this->passwordExternal = "devpass";
$this->port = 9906;
}
$this->connectExtern();
}
private function connectExtern(){
if (null !== $this->connectionExtern)
{
return true;
}
$this->connectionExtern = new mysqli($this->servernameExternal, $this->usernameExternal, $this->passwordExternal, $this->databaseExternal, $this->port);
if ($this->connectionExtern->connect_error) {
throw new Exception("Connection failed: " . $this->connectionExtern->connect_error);
die("Connection failed: " . $this->connectionExtern->connect_error);
}
}
public function getConnection(){
return $this->connectionExtern;
}
public function disconnect(){
mysqli_close($this->getConnection());
}
function __destruct()
{
// $this->disconnect();
}
}