Connect to Microsoft SQL Server

class DatabaseConnector { private $conn = null; public function __construct() { $server_name = ""; // host name $database = ""; // the database name $username = ""; $password = ""; try { $conn = new PDO("sqlsrv:Server=$server_name;Database=" . $database, $username, $password); $conn -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this -> setConnection($conn); } catch(PDOException $e) { echo "Connection failed: " . $e -> getMessage(); } } /** * Sets the database connection. */ public function setConnection($conn) { $this -> conn = $conn; } /** * Gets the database connection. */ public function getConnection() { return $this -> conn; } /** * Sets the connection to null. */ public function closeConnection() { $this -> conn = null; } }