Reputation: 12140
I need to connect to a MSSQL database from PHP. However, as a server on a remote site is connected, I require the connection to be encrypted.
Is it possible to use encrypt the connection to the MSSQL server using only mssql extension for PHP or alternatively PDO?
Upvotes: 4
Views: 13547
Reputation: 2418
There is 3 things that are important when implementing a secure (encrypted) connection to MSSQL:
Encrypt
and TrustServerCertificate
are often used together.Encrypt = true
and TrustServerCertificate = false
(TrustServerCertificate = true
will also work, but your connection will then be vulnerable to attacks)Code-example from article *1:
$serverName = "serverName";
$connectionInfo = array( "Database"=>"DbName",
"UID"=>"UserName",
"PWD"=>"Password",
"Encrypt"=>true,
"TrustServerCertificate"=>false);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
If you use PDO create an object and pass the relevant params. For a more detailed explanation please see the following article:
Upvotes: 12