4

I have recently starting to learn PHP, and a few things I'm struggling now is the connection to a MSSQLS database. I learned in some well quoted websites that the most common (and best) way for using a SQL DB with PHP is using PDO.

So, this was what I have done so far:

1- Successfully installed the drivers:

extension=php_sqlsrv_55_ts.dll

extension=php_pdo_sqlsrv_55_ts.dll

(I have checked in phpinfo(), and my version of PHP is thread safe)

2- Drivers are recognized in the phpinfo()

3- I keep getting this error:

4- Uncaught exception 'PDOException' with message 'SQLSTATE[IMSSP]: This extension requires the Microsoft SQL Server 2012 Native Client ODBC Driver to communicate with SQL Server.

Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712' in C:\xampp\htdocs\catala4\testdb.php:4 Stack trace: #0 C:\xampp\htdocs\catala4\testdb.php(4): PDO->__construct('sqlsrv:Server=H...', 'USER', 'PASSWORD') #1 {main} thrown in C:\xampp\htdocs\catala4\testdb.php on line 4

when executing this code:

<?php
include_once 'configs.php';

$mysqli = new PDO("sqlsrv:Server=HOST;Database=DATABASE", "USER", "PASSWORD");

I have no idea what is wrong, and i would like some help solving this issue, so my questions are:

  • What exactly is ODBC Driver? Is it the driver needed for the connecting with the SQLS ?
  • Considering i am using PDO to connect to a database, being PDO a middle interface to acess any DB, can i then say that any generic code used by this interface works with all the supported databases?
  • What is the error i am getting and what should i do / where should i find more information to solve the problem?

USING PHP v 5.5.9

enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nick Spot
  • 257
  • 2
  • 4
  • 12
  • you need to install ODBC. that's what the error syas! – mamdouh alramadan Mar 31 '14 at 22:13
  • 1
    The error message is straightforward: it instructs you to install the ODBC driver. Do that first, see if it works or not, and then come back here. The community of SO frowns upon people who don't heed error message instructions. – Dai Mar 31 '14 at 22:13
  • where can i get the driver? The link redirects me to a page with instructions. I am using MSSQLS 2008 RC2 and php 5.5.9. Does the obdc drivers works for any php version? – Nick Spot Mar 31 '14 at 22:28
  • i added to the ph.ini: extension=php_pdo_odbc.dll. The error message stays the same. – Nick Spot Mar 31 '14 at 22:57

3 Answers3

4
  • What exactly is ODBC Driver? Is it the driver needed for the connecting with the SQLS ?

Yes, it is . Please read up on ODBC

  • Considering i am using PDO to connect to a database, being PDO a middle interface to acess any DB, can i then say that any generic code used by this interface works with all the supported databases?

wrong ODBC is the middelware.

  • What is the error i am getting and what should i do / where should i find more information to solve the problem?

Problem: Driver is not installed.

Solution: Download and install ODBC driver.

meda
  • 45,103
  • 14
  • 92
  • 122
0

To fix this same issue i downloaded from

http://www.microsoft.com/es-ar/download/details.aspx?id=35580

click on Download and select the package

sqlncli.msi

which is exactly what is missing.

Hope it helps, worked for me. =)

Xampp 1.8.3-3, PHP 5.5.9, same as you

0

You've just to install MS ODBC Driver 11 for SQL Server from this link

Yacine MEDDAH
  • 1,211
  • 13
  • 17