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?
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:
*1 - http://blogs.msdn.com/b/brian_swan/archive/2011/03/08/sql-server-driver-for-php-connection-options-encrypt.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With