SQL Server Identification to a sql database with sqlsrv_connect

zpgglvta  于 2023-04-28  发布在  其他
关注(0)|答案(1)|浏览(106)

I am trying to connect to my database which is on a microsoft sql server with sqlsrv_connect

But I have an error that shows that the provided certificate chain does not have an authority that is not trusted

Array (
    [0] => Array (
        [0] => 08001
        [SQLSTATE] => 08001
        [1] => -2146893019
        [code] => -2146893019
        [2] => [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: The certificate cha�ne has �t� provided by an autorit� that is not approv�e.
        [message] => [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: The certificate chain has �t� provided by an autorit� that is not approved�.
    )
    [1] => Array (
        [0] => 08001 
        [SQLSTATE] => 08001 
        [1] => -2146893019 
        [code] => -2146893019 
        [2] => [Microsoft][ODBC Driver 18 for SQL Server]The client could not �tablish the connection 
        [message] => [Microsoft][ODBC Driver 18 for SQL Server]The client could not �tablish the connection 
    )

I have heard about :

encrypt=true trustservercertificate=true

But I don't know how to integrate it in my php code without error

<?php

$serverName = "";
$connectionInfo = array(
    "Database" => "Affichage",
    "UID" => "sa",
    "PWD" => "mrsushi"
);
$conn = sqlsrv_connect( $serverName, $connectionInfo );

if ($conn) {
        echo "Connexion établie.<br />";
} else {
        echo "La connexion n'a pu être établie.<br />";
        die( print_r( sqlsrv_errors(), true));
}

?>

A new error come when i try the new code :

La connexion n'a pu être établie.
Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Login failed for user 'sa'. [message] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Login failed for user 'sa'. ) [1] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Cannot open database "Ecran" requested by the login. The login failed. [message] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Cannot open database "Ecran" requested by the login. The login failed. ) [2] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Login failed for user 'sa'. [message] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Login failed for user 'sa'. ) [3] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Cannot open database "Ecran" requested by the login. The login failed. [message] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Cannot open database "Ecran" requested by the login. The login failed. ) )
xtfmy6hx

xtfmy6hx1#

Try this according to https://www.php.net/manual/en/function.sqlsrv-connect.php it references https://learn.microsoft.com/en-us/sql/connect/php/connection-options
TrustServerCertificate 1 or true to trust certificate

<?php

$serverName = "";
$connectionInfo = array(
    "Database" => "Affichage",
    "UID" => "sa",
    "PWD" => "mrsushi",
    "TrustServerCertificate" => true
);
$conn = sqlsrv_connect( $serverName, $connectionInfo );

if ($conn) {
        echo "Connexion établie.<br />";
} else {
        echo "La connexion n'a pu être établie.<br />";
        die( print_r( sqlsrv_errors(), true));
}

?>

相关问题