2

I'm trying to connect to a MsSQL server database with php pdo, but I get this error:

Could not find driver.

I've tried all solutions on stackoverflow none of them worked.

  • Installed php driver and configured php.ini. added these one by one:

    extension=php_pdo_sqlsrv_71_ts.dll

    extension=php_sqlsrv_71_ts.dll

    extension=php_pdo_sqlsrv_71_nts.dll

    and all of them at once.

  • Used the pdo_dblib_mssql class: https://www.php.net/manual/en/ref.pdo-dblib.php.

  • Used different PDO constructors:

$conn = new PDO ("dblib:host=$hostname:$port;dbname=dbname","username","pwd");

and

$conn = new PDO("sqlsrv:Server=$servername;Database=dbname", "username", "pwd");

Nothing worked, any help would be appreciated.

PHP version : 7.1.27 / MsSQL SERVER 2014.

Creeper
  • 386
  • 3
  • 16

1 Answers1

1

I found the answer from the comments:

  • Download and install ODBC Driver

  • Configure php.ini file by uncommenting this line: extension=php_odbc.dll

  • Restart xampp

  • use this method to connect :

odbc_connect ( "Driver={SQL Server};Server=$servername;Database=$dbname" , $username ,  $password);
Creeper
  • 386
  • 3
  • 16