How to connect to a MSSQL Server With PHP

I recently had to connect to an MSSQL Server using PHP on an Ubuntu system using PHP. To connect to MSSQL using PHP 5.6 we’ll need to use PDO’s DBLIB (PDO_DBLIB). So let’s install the required packages using following commands:

Installing FreeTDS & Dependencies

All set!, now you should be able to get access to the SQL server database with PHP. Let’s test it with below code

If you get error like below shown
SQLSTATE[01002] Adaptive Server connection failed (severity 9)

change the connection string parameters like shown below –

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments Protection Status
Would love your thoughts, please comment.x