How to use PDO with PHP 5.5 and MSSQL

16,383
  • 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.

Share:
16,383
Nick Spot
Author by

Nick Spot

Updated on June 30, 2022

Comments

  • Nick Spot
    Nick Spot almost 2 years

    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