Windows PHP connection to MSSQL database

Not cold 2019-05-26 Code a line of code five thousand seven hundred and fifty-six

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. MSSQL connection for PHP Download: https://docs.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql -server-2017

Extended 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 PHP installation directory, and add the extension in php.ini

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

 image.png

The driver can be downloaded according to the corresponding 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('127.0.0.1', $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 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

 Z-blog theme readlite release

Z-blog theme readlite release

A light and concise theme, from Lofter Readlite is concise and focuses on reading experience. Take a look at the renderings.. There is no navigation, there is only one page in the front page

Comment list

 Xiaoqing blog
Xiaoqing blog
2022-08-11

It's time to renew, cold

 Software library
2022-06-30

Webmaster, it's time to update.

 I am Huang Jiaju
I am Huang Jiaju
2022-05-30

The author has modified the Tencent cloud CDN plug-in in zblog, which can not be used normally. CDN update failed
www.seeorsee.com
www.uogo.net

 Small earning space

It's time to update the article.

 We media operation

It has to be good!

 Sant UPS
2021-11-01

Support the owner

 Baby rabbit games
2021-10-20

As the ranking of the old station is really good.

 black bear
2021-10-10

Take a first floor and support it

 Beijing kestar
2021-09-01

Take the first floor. Ha ha

 Kestar UPS battery

What the blogger said is good, support

 Green storage machine

Thanks for sharing

 Amazon Gift Card
2021-08-15

Good thing. Thank you~~~~~~

 Xuzai
2021-08-12

I learned. Welcome to visit.

 Perfume essence
2021-07-20

Good job, blogger

 Online earning
Online earning
2021-07-08

Online earning project: www.nizhouqian.com

 News headlines
2021-05-22

Good article. Make a friend

 Natural gas wall hanging furnace manufacturer

Blogger wrote very carefully, thank you for sharing

 Jueyou College
2021-05-18

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

 www
www
2021-05-12

www.sddlzk. How does his ranking go up

 Business opportunity Library

Blog is great, welcome to visit me

 Look for it
2021-01-30

Give the blogger some praise!

 The latest movie in 2021

Bloggers write well!!!

 baidu.zhizhuowz.com

Open it, like it, come on

 A complete collection of classic sentences
A complete collection of classic sentences
2021-01-12

Give the blogger some praise!

 Bear blog
2020-10-30

Under the windows environment, PHP connection to MSSQL is still very simple.

 ghost stories
2020-10-10

Daily clock in ~ refueling-_-

 Summer blog
2020-09-23

Webmaster, it's time to update.

 Duyuan war
2019-05-26

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

Take the first floor. Ha ha

Comment

 visitor

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