Current location: home page > programming >PHP connection to MSSQL database in Windows environment

PHP connection to MSSQL database in Windows environment

Precocious 5 years ago (2019-05-26) programming ten thousand five hundred and sixty-six thirty-six

A few days ago, a project database used MSSQL. Then I need to call the data in it for analysis. Because I am good at PHP, I want to use PHP directly to connect to MSSQL.

Generally, the database used by PHP is MySQL, so you need to install the extension first to make PHP support MSSQL, and Microsoft has the corresponding extension download.

The general steps are as follows:

1. Download the PHP extension for connecting to MSSQL: -server-2017

Extension download address: -server-2017


? You can see the extended version for each version. I downloaded the latest 5.6, because the PHP version uses 7.3.2

After downloading, copy the corresponding dll crisis to the ext directory of the php installation directory, and add extensions in php. ini:

 extension=php_pdo_sqlsrv_73_nts_x64 extension=php_sqlsrv_73_nts_x64

2. After installing the extension, you also need to install the corresponding ODBC driver on the computer: -server-2017


Download and install the driver according to the corresponding extension version.

3. Connect MSSQL

If Larave is used, set DB_CONNECTION to sqlsrv in. env.

If you use PHP connection directly:

 $connectionInfo = array(     "Database" => 'table',     "UID"      => 'sa',     "PWD"      => '123456' ); $conn = sqlsrv_connect('', $connectionInfo); if ($conn) {     $sql = "select * from users;     $data = sqlsrv_query($conn, $sql); }

Copyright notice: Weihan Blog Released. If it needs to be reproduced, please indicate the source.

Link to this article:

Comment List

 New hope
8 months ago (09-28)

Worship the boss.

11 months ago (06-15)

This blog is really good. Come and support the blogger. Welcome to my blog~vipquanwang º C0M

 Taro paste garden
1 year ago (2023-04-28)

Your writing is very clear, which makes it easy for me to understand your point of view.

 Nine gods
1 year ago (2023-03-04)

Ha ha ha ha ha ha

 Summer Blog
1 year ago (2023-02-26)

PHP is usually used with MYSQL.

 Xiaoqing Blog
Xiaoqing Blog
2 years ago (2022-08-11)

It's time to update, cold

 Software library
2 years ago (2022-06-30)

Webmaster, it's time to update.

 I'm Huang Jiaju
I'm Huang Jiaju
2 years ago (2022-05-30)

The author has modified the Tencent Cloud CDN plug-in in the zblog, which can no longer be used normally, and the CDN update failed

 Small profit space
2 years ago (2022-03-23)

It's time to update the article.

 We Media Operation
2 years ago (2021-12-09)

Yes, I must stand up!

 Santak ups
3 years ago (2021-11-01)

Support building owner

 Baby Rabbit Game Network
3 years ago (2021-10-20)

As an old station, the ranking is really good.

 black bear
3 years ago (2021-10-10)

First occupy the first floor to support

 Beijing Keshida
3 years ago (2021-09-01)

First occupy the first floor Ha ha

 Beijing Keshida
3 years ago (2021-09-01)

Thank you, blogger

 Keshida UPS power battery
3 years ago (2021-09-01)

The blogger said very well and supported

 Ensilage machine
3 years ago (2021-08-31)

Thanks for sharing

 Amazon gift card
3 years ago (2021-08-15)

Good thing Thank you~~~~~~

 Xu Zai
3 years ago (2021-08-12)

Learned. Welcome to.

 Perfume essence
3 years ago (2021-07-20)

Good blogger

 Online earning
Online earning
3 years ago (2021-07-08)

Online earning project:

 News headlines
3 years ago (2021-05-22)

Good article, make friends

 Natural gas wall mounted furnace manufacturer

The blogger wrote carefully, thanks for sharing

 Juyou College
3 years ago (2021-05-18)

Come and have a look! Look at the website I made with zblog:

3 years ago (2021-05-12) How to improve his ranking

 Business opportunity library
3 years ago (2021-02-25)

Great blog Welcome to visit me

 Look for it
3 years ago (2021-01-30)

Like the blogger!

 Latest film in 2021
3 years ago (2021-01-30)

The blogger writes well!!!
3 years ago (2021-01-12)

Open, like, come on

 Complete Classic Sentences
Complete Classic Sentences
3 years ago (2021-01-12)

Like the blogger!

 Bear Blog
4 years ago (2020-10-30)

In the Windows environment, PHP is still very simple to connect to MSSQL.

 ghost stories
4 years ago (2020-10-10)

Daily clocking~refueling-_-

 Summer Blog
4 years ago (2020-09-23)

Webmaster, it's time to update.

 Duyuan Shang
5 years ago (2019-05-26)

What a coincidence! The boss hasn't updated for a long time. Is he too tired from work? It can't be 996!

 Duyuan Shang
5 years ago (2019-05-26)

First occupy the first floor Ha ha



 I can't see it clearly. Change it

◎ Welcome to participate in the discussion. Please express your views and opinions here.