I have already done this through Windows machine but getting error on Linux. I have been searching for the similar issues and implementing all I could get, but still no luck.
I am trying to connect SQL server on following environment: Microsoft SQL Server 2016, Linux Centos 7.9.2009, PHP 7.3.29, ODBC Driver 13 and 17
I have already install and enable the PDO_ODBC and pdo_sqlsrv, confirmed through phpinfo.
Below is my connection string:
$conn = new PDO("odbc:Driver={ODBC Driver 13 for SQL Server};SERVER=192.168.99.237;Port:24115;Database=dbname;Uid=username;Pwd=password;")
also tried
$conn = new PDO("odbc:Driver={ODBC Driver 13 for SQL Server};SERVER=192.168.99.237,24115;Database=dbname;", "username", "password")
and the error is
SQLSTATE[HYT00] SQLDriverConnect: 0 [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired
Updated code and findings:
I am able to connect via cli:
isql MSSQL username password
tsql -S MSSQL -U 'username' -P 'password'
osql -S mssql -U username -P password
While trying through below PHP connection string, getting 'could not find driver'
new PDO("dblib:host=mssql;dbname=database", "username", "password");