Skip to content

Instantly share code, notes, and snippets.

@vpetkovic
Created October 15, 2019 19:04
Show Gist options
  • Save vpetkovic/e2c36dca56c53996921e25dbcae79652 to your computer and use it in GitHub Desktop.
Save vpetkovic/e2c36dca56c53996921e25dbcae79652 to your computer and use it in GitHub Desktop.
<?php
class config
{
private static $instance;
public function __construct()
{
self::$instance = $this->dbConnect();
}
public function appSettings() {
// Enter the site name
$_SITENAME_ = '[Site Name]';
// Database Server
$_SRV_ = '[IP]';
// Choose desired environment. 'Prod' or 'Dev'
$_DB_ = '[DB]';
return array(
"AppName" => $_SITENAME_,
"Server" => $_SRV_,
"DB" => $_DB_
);
}
public function dbConnect() {
$app = $this->appSettings();
$serverName = $app['Server']; //serverName\instanceName
$UID = array( "Database"=>$app['DB'], "UID"=>"[user]", "PWD"=>"[pass]"); // For use with username and password not win authentication
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>$app['DB']);
return sqlsrv_connect( $app['Server'], $connectionInfo);
}
public function user() {
$username = getenv("LOGON_USER");
$username = explode("\\", $username);
$username = $username[1];
return $username;
}
// Getting already active db instance
public function getInstance() {
if (empty(self::$instance)) {
self::$instance = $this->dbConnect();
}
return self::$instance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment