PHP connection to MSSQL database in Windows environment

Precocious 2019-05-26 Code one line of code nine thousand eight hundred and eighty-eight

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); }

Related articles

 Zblog topic - MANIFEST test

Zblog topic - MANIFEST test

I spent more than a day imitating this theme. The original version is the theme of WP, and I transplanted it to zblog

 Zblog Topic Manifest Sharing

Zblog Topic Manifest Sharing

I have used this theme for a long time, although I haven't updated it in this period of time

 Z-blog theme ReadLite release

Z-blog theme ReadLite release

A light and simple theme, derived from LOFTER ReadLite is concise and focuses on reading experience. Look directly at the renderings.. One home page, one article page (this topic has no sidebar, no classification, no navigation, only up and down page (article) navigation, only 14

 Z-Blog WeChat subscription

Z-Blog WeChat subscription

It took two days to get the Z-Blog plug-in of WeChat public platform, and its API was used to simply check the latest articles and search for articles with keywords. The latest article is as follows: At the same time, the plug-in also comes with a concise version of the article page to optimize reading articles on WeChat, such as the

 Sublime Text 3 build 3143 Chinese version settings

Sublime Text 3 build 3143 Chinese version settings

Sublime Text 3, which has not been updated for thousands of years, has been updated. The new version has carried out many optimizations and high DPI optimization support. Sublime Text 3 download address: Now if there is Chinese culture

Comment List

 New hope

Worship the boss.


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

 Taro paste garden

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

 Nine gods

Ha ha ha ha ha ha

 Summer Blog

PHP is usually used with MYSQL.

 Xiaoqing Blog
Xiaoqing Blog

It's time to update, cold

 Software library

Webmaster, it's time to update.

 I'm Huang Jiaju
I'm Huang Jiaju

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

It's time to update the article.

 We Media Operation

Yes, I must stand up!

 Santak ups

Support building owner

 Baby Rabbit Game Network

As an old station, the ranking is really good.

 black bear

First occupy the first floor to support

 Beijing Keshida

First occupy the first floor Ha ha

 Beijing Keshida

Thank you, blogger

 Keshida UPS power battery

The blogger said very well and supported

 Ensilage machine

Thanks for sharing

 Amazon gift card

Good thing Thank you~~~~~~

 Xu Zai

Learned. Welcome to.

 Online earning
Online earning

Online earning project:

 News headlines

Good article, make friends

 Natural gas wall mounted furnace manufacturer

The blogger wrote carefully, thanks for sharing

 Juyou College

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

2021-05-12 How to improve his ranking

 Business opportunity library

Great blog Welcome to visit me

 Look for it

Like the blogger!

 Latest film in 2021

The blogger writes well!!!

Open, like, come on

 Complete Classic Sentences
Complete Classic Sentences

Like the blogger!

 Bear Blog

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

 ghost stories

Daily clocking~refueling-_-

 Summer Blog

Webmaster, it's time to update.

 Duyuan Shang

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

First occupy the first floor Ha ha



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