PHP connection to MSSQL database in Windows environment

Precocious 2019-05-26 Code one line of code six thousand nine hundred and ninety-five

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, select DB in. env_ Set Connection to sqlsrv.

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

 Image upload program Mo Lan modified version

Image upload program Mo Lan modified version

Last month, I bought the unlimited space of JustHost and moved all the pictures to the outside chain. Later, for convenience, I put up an image uploading program I used before, but every time I want to upload pictures

 Zblog topic - imitating QQMailService

Zblog topic - imitating QQMailService

Yesterday, there was no content. It was a simple theme. It imitated the service center of QQMail. The theme interface: the logo has not been changed for the time being. Just change the Logo.gif file under the style/help folder in the theme directory

 Z-Blog theme Codename release, including version 2.0

Z-Blog theme Codename release, including version 2.0

The Z-Blog theme Codename is inspired by Windows Live. The main features are as follows: The sidebar design uses the latest sidebar management function of Z-Blog2.0 to directly set the sidebar items to be displayed in the foreground in the background. Comments in line with Z-Blog2.0

 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

 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.