7

I have a working connection to an MSSQL server via PHP PDO.

$mssql = new PDO('dblib:host=1.2.3.4;dbname=databasename', 'username', 'password');

I now need this connection to be secure, sending all transactions over SSL. I do not see any references to secure connections in the PHP manual for the DBLIB driver.

Can someone provide some insight on how I might enable this connection over SSL? (I have the ability to export and import certificates across both servers, if needed.)

EDIT: I'm on PHP 5.5.9.

Drew
  • 24,851
  • 10
  • 43
  • 78
Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131
  • Any resolution to this? Added a tag (`sql-server`). Also see http://stackoverflow.com/a/9768753/1816093 – Drew Sep 12 '15 at 14:18
  • $mssql = new PDO('dblib:host=1.2.3.4;dbname=databasename;Encrypt=1', 'username', 'password'); per http://php.net/manual/en/ref.pdo-sqlsrv.connection.php – hanshenrik Sep 16 '15 at 21:22
  • wups, that's if you're using PDO_SQLSRV , not PDO_DBLIB ... try changing the driver? PDO_SQLSRV is documented to support ssl and MSSQL :/ – hanshenrik Sep 16 '15 at 21:25
  • not sure if this is answering your query visit http://stackoverflow.com/questions/9738712/connect-to-remote-mysql-server-with-ssl-from-php – user1175370 Sep 22 '15 at 14:18
  • Possible [duplicate](http://stackoverflow.com/questions/22294221/php-pdo-connect-to-ms-sqlserver-express-using-ssl/33322487#33322487) – Kyle Wiering Oct 31 '15 at 15:37
  • Look here: http://stackoverflow.com/questions/309615/connect-to-a-mysql-server-over-ssh-in-php – Markus Zeller Jan 06 '17 at 16:49

2 Answers2

0

Not sure on your server setup, but the 'official' way to do this is with the Microsoft's drivers. Unfortunately, they only work with SSL for Windows PHP servers. Here are the connection options.

If you are on Linux, there is one option that does SSL, but it isn't officially MS supported.

Kyle Wiering
  • 444
  • 5
  • 15
0

I know its abit late to post this out as its 6 years later, but currently ive got this solution using PDO with mssql. However i am using ODBC with MSSQL, this is what i did to get the PDO working with XAMPP as localhost

Apparently, odbc&mssql does not require complicated like this

$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);

but just simple

$conn = new PDO ("odbc:$dbname", $username, $password);

This is the working code for my sysyem

 $dbname = "Form_Database";
    $username = "";
    $password = "";

    try{
        $conn = new PDO ("odbc:$dbname", $username, $password);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        $stmt = $conn->prepare("<--SQL QUERY-->");
        $stmt -> execute();
        $result = $stmt -> setFetchMode(PDO::FETCH_ASSOC);
        
    } catch(PDOException $e) {
      echo "Error: " . $e->getMessage();
    }
Steve Kush
  • 143
  • 1
  • 13