Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server

Tags:

php

sql-server

ALready downloaded the sqlsrv on microsoft...

enter image description here

and on my phpinfo()

enter image description here

enter image description here

enabled on php.ini on both C:\wamp\bin\apache\apache2.4.9\bin and C:\wamp\bin\php\php5.5.12 enter image description here

and still got error like this.

Failed to get DB handle: SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712  

and my code is

try {     $dbh = new PDO ("sqlsrv:Server=$host;Database=$db","$user","$pass");   } catch (PDOException $e) {     echo "Failed to get DB handle: " . $e->getMessage() . "\n";     exit;   }   $stmt = $dbh->prepare("select top 5 from teams");   $stmt->execute();   while ($row = $stmt->fetch()) {     print_r($row);   }   unset($dbh); unset($stmt); 
like image 820
Storm Spirit Avatar asked Dec 21 '15 17:12

Storm Spirit


People also ask

Which ODBC driver should I use for SQL Server?

Microsoft ODBC Driver for SQL Server (MSODBCSQL) Driver history for Microsoft SQL Server recommends this driver in preference to "SQL Server" and "SQL Server Native Client" for ODBC.


1 Answers

Apart of the pdo_sqlsrv extension, you also need to have the ODBC 11 driver installed on your machine.

You can get it at one of these locations:

  • https://www.microsoft.com/en-us/download/details.aspx?id=36434
  • https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017
like image 115
Mark Avatar answered Sep 19 '22 04:09

Mark