0

I am trying to access a MS SQL server using Windows Authentication. I found an example and tried to follow that (see code below), but every time I load the page I get

exception 'PDOException' with message 'could not find driver' in C:\wamp\www\test.php:34 Stack trace: #0 C:\wamp\www\test.php(34): PDO->__construct('sqlsrv:Server=P...', NULL, NULL) #1 {main}"

<?php

try {
   $conn = new PDO( "sqlsrv:Server=SERVERHOSTNAME/DPA1" ); 
   $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}

catch( PDOException $e ) {
   echo $e; 
}

?>
Bryan
  • 63
  • 5
  • http://www.microsoft.com/en-us/download/details.aspx?id=20098 – Mihai Jul 03 '14 at 21:47
  • @Mihai That driver only supports PHP 5.3 and above (after mssql was removed from PHP). I downloaded the 2.0 version of that driver (SQLSRV20.exe) and installed it by adding the following lines to my php.ini file: extension=php_sqlsrv_52_nts_vc6.dll; extension=php_sqlsrv_52_ts_vc6.dll; WAMP5 Homepage now shows that the sqlsrv php extension is installed, but I still get the same error message. It looks like to connect using the sqlsrv drivers you have to call sqlsrv_connect(), but Ive not seen any tutorials which instruct me to use that when logging in with Windows Authentication – Bryan Jul 03 '14 at 22:28
  • Maybe is not related to sql server http://stackoverflow.com/questions/2852748/pdoexception-could-not-find-driver Im not sure older versions of PHP have PDO.. – Mihai Jul 03 '14 at 22:45

1 Answers1

2

I am assuming that you are using XAMPP/WAMPP/MAMMP. You need to set the mssql-driver to connect to your database using PHP.

You can find that driver here:

https://www.microsoft.com/en-us/download/details.aspx?id=20098

Then you can add it in your php.ini file in your service host in XAMPP.

You can find a good tutorial on this post:

PHP 5.4 and MsSQL on XAMPP

Good luck!

Community
  • 1
  • 1