PHP PDO for SQL SERVER

Asked

Viewed 608 times

1

Good afternoon,

I am trying to connect with my PHP pages in MS SQL SERVER using PDO, but I am having difficulties. I tried to use the PHP manual, but I’m getting confused and I’m not getting it. The page is returning this error: Failed to get DB Handle: could not find driver. I tried to download the drivers from the microsoft site, but it didn’t work either. I looked here at the forum and nothing tbm, I looked at these posts: PDO Drivers for SQL Server How to connect PHP 5.6 to Sql Server 2008? Error while trying to connect bd MSSQL Server using PDO

OBS.: I am using windows 10; PHP version 5.6.25; SQL SERVER 2014 EXPRESS;

Thank you!

  • I was able to connect using pdo_odbc, but I felt that the connection is a little slow.

  • Related: http://answall.com/questions/175222/n%C3%A3o-estou-conseguir-configurar-os-drivers-do-sqlsrv-no-php7/175226#175226

  • As I understand it, the problem in this case is that Windows 10 needs at least version 4.0 of the driver and PHP 5.6 requires version 3.2 of the driver. More information here: https://www.dirceuresende.com/blog/howto connect to no-sql-server-using-o-php-xampp-e-o-driver-pdo-windows/

1 answer

0

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.6, Download SQLSRV32 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. in the case of the example you will have to copy the dlls that have _ts.dll from php 5.6, i.e.: php_pdo_sqlsrv_56_ts.dll and php_sqlsrv_56_ts.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_56_ts.dll Extension=php_pdo_sqlsrv_56_ts.dll

and remove ";" from line Extension=php_pdo_odbc.dll, if still commented.

php.ini 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.

  • Sorry for the delay in responding, I did exactly the steps mentioned above, tried with virtually all the dll’s I found and even then it didn’t work.

Browser other questions tagged

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