First of all, I'm really a noob. (Feel sorry) Secondly, I tried to connect php to mssql server. Third, I have installed sqlsrv, pdo_sqlsrv and msodbcsql.msi But still getting error message when trying to connect
My php version is 8.0.10, x64; mssql server 2012.
My php code for testing the connection:
<?php $serverName = "10.xxx.xx.148"; $connectionInfo = array( "Database"=>"zzzz", "UID"=>"ww","PWD"=>"123cccc"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true));} ?>
Then I got an error and was instructed to install msodbcsql.msi, I installed it as instructed. But then it shows new errors which I can't solve.
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 1 => -2146893019 [Code] => -2146893019 2 => [Microsoft][ODBC Driver 18 for SQL Server] SSL Provider: The certificate chain was issued by an untrusted authority. [Message] => [Microsoft][ODBC Driver 18 for SQL Server] SSL Provider: The certificate chain was issued by an untrusted authority. issued by the agency.) 1 => Array([0] => 08001 [SQLSTATE] => 08001 1 => -2146893019 [Code] => -2146893019 2 => [Microsoft][ODBC Driver 18 for SQL Server]Client cannot establish connection [Message] => [Microsoft][ODBC Driver 18 for SQL Server]Client cannot establish connection) )
Additional information: There is no problem when I connect dbeaver (different computer) to mssql server (same server).
Thank you in advance
I used ODBC driver 17 instead of ODBC driver 18 and the problem was solved. In my case I don't need encryption so driver 17 is fine for me.
Just in case anyone is wondering how to define the TrustServerCertificate as 1, this is how I did it, I added the parameters as new array elements like this