PHP connection to MSSQL database in Windows environment

Precocious 2019-05-26 Code one line of code six thousand nine hundred and seventy-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: https://docs.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql -server-2017

Extension download address: https://docs.microsoft.com/zh-cn/sql/connect/php/download-drivers-php-sql-server?view=sql -server-2017


 image.png

? 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: https://docs.microsoft.com/zh-cn/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql -server-2017

 image.png

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('127.0.0.1', $connectionInfo); if ($conn) {     $sql = "select * from users;     $data = sqlsrv_ query($conn, $sql); }


Related articles

 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

 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 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

 Z-blog theme ReadLite release

Z-blog theme ReadLite release

A light and simple theme, derived from LOFTER.ReadLite's simple reading, focuses on the 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

Comment List

 Taro paste garden
2023-04-28

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

 Nine gods
2023-03-04

Ha ha ha ha ha ha

 Summer Blog
2023-02-26

PHP is usually used with MYSQL.

 Xiaoqing Blog
Xiaoqing Blog
2022-08-11

It's time to update, cold

 Software library
2022-06-30

Webmaster, it's time to update.

 I'm Huang Jiaju
I'm Huang Jiaju
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
www.seeorsee.com
www.uogo.net

 Small profit space

It's time to update the article.

 We Media Operation

Yes, I must stand up!

 Santak ups
2021-11-01

Support building owner

 Baby Rabbit Game Network

As an old station, the ranking is really good.

 black bear
2021-10-10

First occupy the first floor to support

 Beijing Keshida
2021-09-01

First occupy the first floor Ha ha

 Beijing Keshida
2021-09-01

Thank you, blogger

 Keshida UPS power battery

The blogger said very well and supported

 Ensilage machine
2021-08-31

Thanks for sharing

 Amazon gift card
2021-08-15

Good thing Thank you~~~~~~

 Xu Zai
2021-08-12

Learned. Welcome to.

 Online earning
Online earning
2021-07-08

Online earning project: www.nizhuanqian.com

 News headlines
2021-05-22

Good article, make friends

 Natural gas wall mounted furnace manufacturer

The blogger wrote carefully, thanks for sharing

 Juyou College
2021-05-18

Come and have a look! Look at the website I made with zblog: http://www.jsyp.cc

 www
www
2021-05-12

Www.sddlzk.com How to improve his ranking

 Business opportunity library

Great blog Welcome to visit me

 Look for it
2021-01-30

Like the blogger!

 Latest film in 2021

The blogger writes well!!!

 baidu.zhizhuowz.com

Open, like, come on

 Complete Classic Sentences
Complete Classic Sentences
2021-01-12

Like the blogger!

 Bear Blog
2020-10-30

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

 ghost stories
2020-10-10

Daily clocking~refueling-_-

 Summer Blog
2020-09-23

Webmaster, it's time to update.

 Duyuan Shang
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
2019-05-26

First occupy the first floor Ha ha

Comment

 visitor

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