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-four 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: 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, set DB_CONNECTION to sqlsrv in. env.

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


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

Link to this article: https://imzhou.com/archives/293.html

Related articles

Zblog Topic Manifest Sharing 13 years ago (2011-11-19)
Z-blog theme ReadLite release 12 years ago (2012-12-25)
Z-Blog WeChat subscription 11 years ago (2013-04-16)

Comment List

 New hope
8 months ago (09-28)

Worship the boss.

 coupon
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
www.seeorsee.com
www.uogo.net

 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: www.nizhuanqian.com

 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: http://www.jsyp.cc

 www
www
3 years ago (2021-05-12)

Www.sddlzk.com 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!!!

 baidu.zhizhuowz.com
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

Comment

 visitor

 I can't see it clearly. Change it

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