Windows PHP connection to MSSQL database

Not cold 2019-05-26 Code a line of code five thousand eight hundred and twenty-eight

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

Generally, the database used by PHP is mysql. Therefore, we need to install the extension first to make PHP support MSSQL. Microsoft official has the corresponding extension download.

The steps are as follows:

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

Extended 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 the extension to the directory of php.php, copy the extension to the directory of PHP

 extension=php_ pdo_ sqlsrv_ 73_ nts_ x64 extension=php_ sqlsrv_ 73_ nts_ x64

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


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

3. Connect to MSSQL

If you are using larravel, set dB in. Env_ Set connection to sqlsrv.

If you are using PHP 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 modified by Mo LAN

Image upload program modified by Mo LAN

Last month, I bought the unlimited space of justhost, and then I moved all the pictures to the outside chain. Later, for convenience, I put a picture upload program that I used to use before, but every time I want to upload pictures

 Zblog topic - manifest test

Zblog topic - manifest test

It took more than a day to imitate this theme. The original version is the theme of WP. I transplanted it to zblog

 Zblog theme - imitating qqmailservice

Zblog theme - imitating qqmailservice

I did it yesterday. There is no content. It is a very simple theme. It imitates the service center of qqmail. The theme interface: logo has not been changed for the time being. I can change the logo.gif file under the style / help folder in the theme directory

 Zblog theme manifest sharing

Zblog theme manifest sharing

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

 Z-blog theme codename released, including version 2.0

Z-blog theme codename released, including version 2.0

Z-blog theme codename, inspired by Windows Live. The main features are as follows: the sidebar design uses the latest sidebar management function of z-blog2.0, which can directly set the sidebar items to be displayed in the foreground in the background. Comments in line with Z-blog 2.0

Comment list

 Xiaoqing blog
Xiaoqing blog

It's time to renew, 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 zblog, which can not be used normally. CDN update failed

 Small earning space

It's time to update the article.

 We media operation

Yes, I have to do it!

 Sant UPS

Support the owner

 Baby rabbit games

As the ranking of the old station is really good.

 black bear

Take a first floor and support it

 Beijing kestar

Take the first floor. Ha ha

 Beijing kestar

Thank you for your education

 Kestar UPS battery

What the blogger said is good, support

 Green storage machine

Thanks for sharing

 Amazon Gift Card

Good thing. Thank you~~~~~~


I learned. Welcome to visit.

 Perfume essence

Good job, blogger

 Online earning
Online earning

Online earning project:

 News headlines

Good article. Make a friend

 Natural gas wall hanging furnace manufacturer

Blogger wrote very carefully, thank you for sharing

 Jueyou College

Come and have a look! Look at my website with zblog:


www.sddlzk. How does his ranking go up

 Business opportunity Library

Blog is great, welcome to visit me

 Look for it

Give the blogger some praise!

 The latest movie in 2021

Bloggers write well!!!

Open it, like it, come on

 A complete collection of classic sentences
A complete collection of classic sentences

Give the blogger some praise!

 Bear blog

It's still very simple to connect in msphp.

 ghost stories

Daily clock in ~ refueling-_-

 Summer blog

Webmaster, it's time to update.

 Duyuan war

What a coincidence, the boss hasn't updated for a long time. Is it too tired to work? It won't be 996!

 Duyuan war

Take the first floor. Ha ha



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