<?php
function getDB(): PDO {
	static $db = null;
	if ($db instanceof PDO) return $db;

	$host = '192.168.10.61';
	$port = 1433;
	// Credentials updated when DB changed
	$user = 'zack';
	$pass = 'zack123456';

	// Do not specify a default Database so cross-database queries using fully-qualified names work.
	$dsn = "sqlsrv:Server={$host},{$port}";

	try {
		$db = new PDO($dsn, $user, $pass);
		$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
		return $db;
	} catch (PDOException $e) {
		error_log('DB connect error: ' . $e->getMessage());
		throw $e;
	}
}