PDO Drivers for SQL Server

Asked

Viewed 18,167 times

14

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

could not find driver

I’ve tried enabling features in php.ini but failed!

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

  • 1

    Which version of php you’re using?

  • 2

    the version is 5.5.8

3 answers

14


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

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

1 - Download the microsoft website driver at that link

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

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

4 - Finally add the upload of the extension to 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 check if extension has been loaded correctly create a new file with the code:

<?php
    phpinfo();

If you have no problem phpinfo will be loaded as the image below:

inserir a descrição da imagem aqui

Another way to check if the PDO driver has been installed correctly is to use getAvailableDrivers()

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

The result is something like:

Array
(
    [0] => mysql
    [1] => sqlsrv
    [2] => pgsql
    [3] => sqlite
)
  • The official release of 5.5 finally came out!

  • We still don’t have an official release of SQL Drivers that supports PHP 5.6, but we can show that it is something important voting here

  • @gmsantos, exit php5.6 driver, is the SQLSRV32.EXE.

  • Yeah, I’ve been using it for a while. I hope it doesn’t take you so long to release the PHP 7 compatible release =)

3

You will need some . dll files that you can find in the following link: https://www.microsoft.com/en-us/download/details.aspx?id=20098 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 which PHP Extension Build. PHP Extension Build
(source: sysadminslife.with) . in the case of the example you will have to copy the dlls that have _nts.dll from php 5.5, i.e.: 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 C:/windows/Syswow64 if you are already a 64bit computer.

Once this is done 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 ";" from line Extension=php_pdo_odbc.dll if still commented.

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

https://www.microsoft.com/pt-br/download/details.aspx?id=36434

After installing the previous steps. you should restart apache.

if everything is correct you can access phpinfo() again and search for sqlsrv sqlsrv

and then by pdo_sqlsrv pdo_sqlsrv
(source: synet.sk)
hope I’ve helped.

  • thanks for your attention, but the problem is so old that I no longer have access to it!

0

Good morning guys!!

It was with the same problem, I performed the steps indicated, however, I did not succeed in installing the Sql Server connection.

Versions:

  • PHP = 5.6.21;
  • OS = Windows Server 2008 R2 Enterprise SP1.

I installed the following components:

  • Copy of Dlls to the ext php folder: php_sqlsrv_56_ts.dll and php_pdo_sqlsrv_56_ts.dll (my php is for Thread Safety as per DLL "php5ts.dll");

  • I added in the file "php.ini" the extensions: "Extension=php_pdo_sqlsrv_56_ts.dll" and "Extension=php_sqlsrv_56_ts.dll";

  • In the image below, it is possible to notice that the extension was not enabled. inserir a descrição da imagem aqui

If anyone can help me...

Thank you!!

  • If you have a new question, please use the button Ask a question. The area you used to post the question is for answers only.

  • The site works different from a forum, to understand the differences recommend reading the [tour]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.