Monday, March 30, 2015

Accessing MSSQL with PHP - Solving Microsoft ODBC Driver Problem

I'm using PHP 5.6.3 with XAMPP (installed using xampp-win32-5.6.3-0-VC11-installer.exe). When trying to connect to MSSQL server database, it trigger error as below (or almost the same error).

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft ODBC Driver 11 for SQL Server....

This error occur after the XAMPP started with sqlserver extension defined in PHP.ini successfully loaded.

Looking at PHP manual @ http://php.net/manual/en/function.sqlsrv-connect.php only shows how to connect. A few more site shares the same things too:

  1. https://support.winhost.com/kb/a687/sample-code-to-connect-to-an-ms-sql-database-using-php.aspx
  2. http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28215738.html
  3. http://www.yiiframework.com/forum/index.php/topic/44474-sqlsrv-connection-fails-to-open/
  4. https://social.msdn.microsoft.com/Forums/sqlserver/en-us/home?forum=sqldriverforphp&sort=lastpostdesc&brandIgnore=true&page=3


Even going to Microsoft MSDN won't help that much.

So, I would like to share the step that you should take if you found or getting the same error:
  1. Go to vimalakanchanamsc.wordpress.com will share the necessary steps and it is really good if you could start from this point forward.
  2. Then, download Microsoft ODBC Driver 11 from Microsoft. Please make sure you select the correct SQL Server version. I'm using SQL Server 2014 and therefore is using the driver from that link. You may used different version of ODBC driver. It also dependent on OS architecture (x86 or x64).
  3. Upon complete this two steps, you should already have 
    • SQLSRV32.exe or SQLSRV30.exe
    • vcredist_x64.exe or vcredist_x86.exe
    • sqlncli.msi
    • msodbcsql.msi
  4. Installed one by one according to the list (from top to bottom). If you already installed, please ignore the file.


My problem of connecting the SQLSERVER in PHP resolved after I've installed all file.

That's all...

Happy PHPing


0 comments :

Share It

Gadget

This content is not yet available over encrypted connections.

Popular Posts