I found that I couldn’t connect to MSSQL on Windows from the WSL side. The ODBC drivers were working as I could connect to a remote instance. source code sample.

So I got MSSQL working on WSL2 which isn’t supported but it works.

https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver16 this is SQL2022 Preview v16 which needs SSMS tools 19 preview to get the profiler working


# run mssql manually
sudo -u mssql /opt/mssql/bin/sqlservr -c -d/var/opt/mssql/data/master.mdf -l/var/opt/mssql/data/mastlog.ldf -e/var/opt/mssql/log/errorlog -x

Then connect from Windows via the IP

alt text which I found doing ifconfig from wsl side.

Then PHP side:

$serverName = "";
database = "OSR4Rights" ;
username = "sa";
password = "secret";

connectionOptions = array(
	"database" => $database,
	"uid" => $username,
	"pwd" => $password,
	"TrustServerCertificate" => true

source code contains gotchas including getting the cursor correct to get the correct rowcount.