
&"$PSScriptRoot\vars.ps1"

#Install PHP sqlsrv.dll
$phpNumber = $PHP_VERSION.replace('.','')
$sqlLib = "php_sqlsrv_" + $phpNumber + "_nts_x64.dll"
if ((-Not (Test-Path "$PHPdir/ext/$sqlLib" -PathType Leaf)))
{
	if (-Not(Test-Path "$ROOT/Var/Upgrade/sqlsrv.zip" -PathType Leaf))
	{
		$url = "https://go.microsoft.com/fwlink/?linkid=2199011"
		Invoke-WebRequest -Uri $url -OutFile "$ROOT/Var/Upgrade/sqlsrv.zip" -SkipCertificateCheck
	}

	Expand-Archive -Force "$ROOT/Var/Upgrade/sqlsrv.zip" -DestinationPath "$ROOT/Var/Upgrade/sqlsrv/"

	Copy-Item "$ROOT/Var/Upgrade/sqlsrv/$sqlLib" "$PHPdir\ext\"
	
	if (Test-Path "$PHPdir/ext/$sqlLib" -PathType Leaf)
	{
		Remove-Item "$ROOT/Var/Upgrade/sqlsrv.zip"
    	Remove-Item -Recurse "$ROOT/Var/Upgrade/sqlsrv/"
	}
}
