How to connect PHP 5.6 to Sql Server 2008?

0

I need to connect to a BD MS Sql Server 2008 with PHP 5.6

I have Development: Windows 7 64bit, with xampp

Centos 7 Production

I have installed the Microsoft drivers .

With this line of code

$c = new PDO("sqlsrv:Server=$host;Database=$db", "$user", "$pwd");

It gives error:

  

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE [IMSSP]: This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86

Probably will not work on Centos 7.

What is the best solution?

    
asked by anonymous 23.09.2015 / 18:52

2 answers

1

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

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

use phpinfo () to check PHP Extension Build. .intheexamplecaseyouwillhavetocopythedllsthathavephp5.6_ts.dll,ie:php_pdo_sqlsrv_56_ts.dll,andphp_sqlsrv_56_ts.dll,Copythesefilestotheirdirectories,C:/.../php/extandalsoC:/windows/system32/and/orC:/windows/SysWOW64ifitisa64-bitcomputer.

Whenyoudothisyoushouldopenphp.iniandintheextensionsessionyoushouldaddthefollowinglines:

extension=php_sqlsrv_56_ts.dll

extension=php_pdo_sqlsrv_56_ts.dll

You will also need to install Microsoft® ODBC Driver for SQL Server [Native Client] that will depend on your database in the case as an 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.

    
22.01.2017 / 23:55
0

Dude, how would you try to connect using the ODBC Driver? No seise helps in your case, but it worked for me like this:

$conexao = new PDO("odbc:Driver={SQL Server};Server=.\SQLEXPRESS;Database=bancoDeDados; Uid=sa;Pwd=SenhaDoBanco;");

Remembering that you should enable the ODBC driver in PHP.ini ...

    
15.09.2016 / 17:27