skip to Main Content

first of all, im really noob.(sorry for that)
secondly, iam trying to connect php to mssql server.
thirdly, i already install sqlsrv, pdo_sqlsrv, and msodbcsql.msi
but still get error message when trying to connect
enter image description here
enter image description here

my php version is 8.0.10, x64;
mssql server 2012.

my code in php to test 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));}
?>

and then i get error, and instruction to install msodbcsql.msi, i install it just like the instruction. but then show new error that iam unable to solved.

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 authority that is not trusted. [message] => [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: The certificate chain was issued by an authority that is not trusted. ) 1 => Array ( [0] => 08001 [SQLSTATE] => 08001 1 => -2146893019 [code] => -2146893019 2 => [Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection [message] => [Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection ) )

additional info: when i connect dbeaver (different pc) to mssql server (same server) there is no problem.

thank you in advance

2

Answers


  1. I used ODBC Driver 17 instead of ODBC Driver 18 and problem solved. In my case I didn’t need encryption so driver 17 was ok for me.

    Login or Signup to reply.
  2. Just in case anyone is wondering how to define the TrustServerCertificate to 1, this is how i did it, i added the parameter as a new array element as shown below

    <?php
    $serverName = "10.xxx.xx.148";
    $connectionInfo = array( 
     "Database"=>"zzzz",
     "UID"=>"ww",
     "PWD"=>"123cccc",
     "TrustServerCertificate"=>true
    );
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search