简体   繁体   中英

php to mssql server errro SSL Provider: The certificate chain was issued by an authority that is not trusted

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在此处输入图像描述 在此处输入图像描述

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

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.

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);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM