Php5.6.8 analysis and summary of common skills of connecting SQL Server 2008 R2 database


This paper introduces the common skills of php5.6.8 connecting to SQL Server 2008 R2 database. To share with you for your reference, as follows:

Tools used:

1. JetBrains phpstorm (write PHP code tool)

2. SQL Server 2008 R2 (database)

3. PHP 5.6. X (x86 from Apache xampp integration)

First, let’s see how many bits PHP is and some information about the thread safety.

Create a PHP file in phpstorm with the contents as follows

 * Created by PhpStorm.
 * User: admin
 * Date: 2018/4/8
 * Time: 16:12
//Display all information. Info "is displayed by default

Mainly obtain x86 and thread TS

Download driver package

Microsoft Drivers for PHP for SQL Server
(I am version 5.6 here, Download sqlsrv32.exe) unzip the sqlsrv32.exe file,



(meaning: 5.6 version, php of thread safe TS)

Copy in

X disk: \ xampp \ PHP \ ext

Inside file

Then add two groups of data to the file PHP. In of the upper layer and modify a configuration place

holdmssql.allow_persistent=OffChange tomssql.allow_persistent=On

After saving.

Open phpstorm and write a code:

 * Created by PhpStorm.
 * User: admin
 * Date: 2018/4/8
 * Time: 14:24
$servername = "(local)"; // database server address
$uid = "Sa"; // database user name
$PWD = "123456"; // database password
$connectionInfo = array("UID"=>$uid, "PWD"=>$pwd, "Database"=>"mysql");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( $conn == false)
  Echo "connection failed! ";
  Echo "link succeeded";

These messages will appear on the page:

Connection failed! Uncaught exception ‘PDOException’ with message ‘SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86:’

Generally according to the prompt:

At this time, you will be prompted to install a Microsoft ODBC driver 11 for SQL server

Go to the website LINKID = 163712

Select and download the correct type number according to the system type of the computer

Then restart the Apache server again

Personal feeling: at first, I was confused and made various mistakes. Then I summarized my own process and clarified my thoughts.

For more information about PHP, please refer to the following topics: summary of PHP database operation skills based on PDO, summary of PHP + Oracle database programming skills, complete database operation skills of PHP + mongodb, introduction to PHP object-oriented programming, summary of PHP string usage, and introduction to PHP + MySQL database operation And PHP common database operation skills summary

I hope that this article will be helpful for PHP programming.