PDO Drivers for SQL Server

13

I'm trying to run a PHP application (version 5.5.8) with the connection to the SQL Server database with PDO, but it returns the following error:

  

could not find driver

I have tried to enable features in php.ini but to no avail!

Remembering that the database is not the problem because I can access it through SQL Management Studio normally.

    
asked by anonymous 23.01.2015 / 18:15

2 answers

13

Regardless of doing a 'clean' installation or just updating some component (OS, PHP, VCxx and MSSQL) it is strongly recommended to check the SQL server driver compatibility with the other components to not install anything wrong. The procedure described below is also used to install the sqlsrv extension.

There is a table which shows which version of the SQL Server driver is compatible with its version of PHP.

1 - Download the microsoft site driver in this link

2 - Unzip the file see driver version with php version and whether it is thread safe or not (see Thread Safety no phpinfo() ).

3 - Copy the dll to the ext folder of the php installation.

4 - Finally add the extension load in php.ini and restart the server.

extension=php_pdo_sqlsrv_VERSAO_THREAD_SAFE_OU_NAO.dll

For non thread safe

extension=php_pdo_sqlsrv_55_nts.dll

For thread safe

extension=php_pdo_sqlsrv_55_ts.dll

To verify that the extension has loaded correctly, create a new file with the code:

<?php
    phpinfo();

If you have no problem, phpinfo will load like the image below:

AnotherwaytocheckifthePDOdriverwasinstalledcorrectlyistouse getAvailableDrivers()

<?php
   echo "<pre>";
   print_r(PDO::getAvailableDrivers());

The result is something like:

Array
(
    [0] => mysql
    [1] => sqlsrv
    [2] => pgsql
    [3] => sqlite
)
    
23.01.2015 / 18:27
2

You will need some .dll files that you can find at the following link:   link Since your PHP is 5.5, download the SQLSRV31 file.

After downloading the file, you will extract it, there you will have the necessary dlls.

use phpinfo () to check PHP Extension Build. PHP Extension Build http://www.sysadminslife.com/wp-content /uploads/2014/01/php5_5-phpinfo-3.jpg . in the case of the example you will have to copy the dlls that have _nts.dll from php 5.5, ie: php_pdo_sqlsrv_55_nts.dll and php_sqlsrv_55_nts.dll, Copy these files to their directories, C: /.../ php / ext and also for C: / windows / system32 / and / or for C: / windows / SysWOW64 if 64-bit computer.

When you do this you should open php.ini and in the extension session you should add the following lines:

extension = php_sqlsrv_55_nts.dll extension = php_pdo_sqlsrv_55_nts.dll

and remove the ";" of the line extension = php_pdo_odbc.dll if it is still commented.

You will also need to install Microsoft® ODBC Driver for SQL Server [Native Client] which will depend on your database in the case of example I will pass the Microsoft® ODBC Driver 11 link to SQL Server.

link

After the previous steps are fully installed. you should restart apache.

If everything is correct you can re-access phpinfo () and you can search for sqlsrv

andthenpdo_sqlsrv pdo_sqlsrv http://www.synet.sk/images/cms/pdo_sqlsrv_phpinfo.png I hope I have helped.

    
23.01.2017 / 00:11