Nick Spot
Nick Spot

Reputation: 267

How to use PDO with PHP 5.5 and MSSQL

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:

USING PHP v 5.5.9

enter image description here

Upvotes: 4

Views: 16899

Answers (3)

spielbug
spielbug

Reputation: 1361

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

Upvotes: 0

Matias Parraga
Matias Parraga

Reputation: 1

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

Upvotes: 0

meda
meda

Reputation: 45490

  • 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.

Upvotes: 4

Related Questions