# Microsoft Drivers for PHP: SQL Server Setup and Use

> The microsoft/msphpsql repository provides the SQLSRV and PDO_SQLSRV PHP extensions for connecting PHP applications to Microsoft SQL Server through Microsoft ODBC Driver 17 or 18. It suits teams using PHP 8.3 or later that need either a procedural or PDO interface.

**microsoft/msphpsql** — Microsoft Drivers for PHP for SQL Server

- Repository: https://github.com/microsoft/msphpsql
- Stars: 1,887 · Forks: 385
- Language: PHP
- License: MIT
- Published: 2026-10-16 · Updated: 2026-10-16 · Language: en
- Canonical page: https://hysenlabs.com/projects/microsoft-msphpsql

## Why microsoft/msphpsql Exists for PHP Applications

The microsoft/msphpsql project addresses a specific integration boundary: PHP code needs to read and write data held in Microsoft SQL Server. It supplies two native PHP extensions for that connection. SQLSRV exposes a procedural interface, while PDO_SQLSRV implements PHP Data Objects for applications that prefer PDO conventions. This makes the project relevant to PHP applications using IIS or Apache, as well as command-line PHP processes, but its target database is SQL Server rather than a database-neutral stack.

The documented target range includes SQL Server 2012 and later on Windows and SQL Server 2016 and later on Linux. Azure SQL DB is also identified as supported. That range matters during planning. A team should not assume that every extension capability or server feature is equally available across those products. The README directs adopters to the system requirements and release pages rather than promising uniform feature coverage.

The driver is aimed at developers who control both the PHP application and its client environment. It is not a standalone database engine, ORM or deployment container. It also does not remove the need for a separate low-level connectivity component: the extensions rely on Microsoft ODBC Driver for SQL Server. That dependency makes operating-system package selection, architecture matching and extension loading part of the actual installation work.

## The SQLSRV and PDO_SQLSRV Connection Path

The architecture has a clear division of responsibility. PHP calls either SQLSRV or PDO_SQLSRV. Those extensions communicate through Microsoft ODBC Driver for SQL Server, which handles low-level communication with the server. This setup gives the repository two choices of programming interface while preserving the same underlying database connectivity path.

SQLSRV suits code that wants direct procedural calls. PDO_SQLSRV is intended for code that already uses PHP Data Objects. The README does not say that the two extensions provide identical feature sets in every situation, so an application should select its interface based on its existing PHP code and verify the relevant behavior in the driver documentation and release limitations.

There is also a runtime compatibility boundary. This release is described as covering PHP 8.3 and later, and its client prerequisites list PHP 8.3.x, 8.4.x and 8.5.x. Microsoft ODBC Driver 18 or 17 is required. If the deployment host runs an older PHP release, does not have either supported ODBC driver, or needs a server outside the documented platform and version matrix, this repository is not a direct fit.

The project ships source code, sample programs and build files, but the usual installation path is not equivalent on every operating system. Windows offers precompiled extensions. UNIX installations are delegated to Microsoft Docs. This difference makes the target operating system a prerequisite that should be settled before choosing a deployment procedure.

## Installing the Windows PHP Extensions

On Windows, the releases page distributes pre-compiled extensions, so compiling the drivers is not required for every deployment. The available builds vary by thread-safe and non-thread-safe modes and by 32-bit or 64-bit architecture. The web server's thread-safety configuration determines which package should be selected.

The driver files must be placed in the PHP extension directory. After that, the appropriate extension must be enabled in `php.ini`. The README gives these configuration entries, with `and/or` showing that one or both can be loaded depending on the chosen interface:

```ini
extension=php_sqlsrv.dll
```

```ini
extension=php_pdo_sqlsrv.dll
```

If PHP does not already locate the extension directory, `extension_dir` can be set. The README warns that precompiled binaries can have different names, in which case the corresponding filename must be substituted in `php.ini` rather than assuming the example names always apply.

```ini
extension_dir = "C:\PHP\ext"
```

After changing `php.ini`, restart the web server if PHP is running under IIS or Apache. The source-built route is available too. It requires the ability to build PHP 8.* without including these extensions, plus the build documentation under `buildscripts/README.md`. The `sample/` directory contains separate `sqlsrv_sample.php` and `pdo_sqlsrv_sample.php` examples that can serve as the first interface-specific use cases after installation.

## Choosing a First SQLSRV or PDO_SQLSRV Connection

The repository's first-use route is documentation-led rather than a self-contained quick-start script. The README links to the `sample/` directory and to Microsoft's PHP SQL Driver code samples. It also directs users to the getting-started page for installation and basic configuration. 

A practical first check is interface selection. If the application already depends on PDO abstractions, start with `PDO_SQLSRV` and consult `sample/pdo_sqlsrv_sample.php`. If it uses function-oriented database access, start with `SQLSRV` and consult `sample/sqlsrv_sample.php`. In both cases, the expected dependency remains the same: Microsoft ODBC Driver 18 or 17 must already be available on the client machine.

For a UNIX host, follow the linked Microsoft installation instructions instead of adapting the Windows `php.ini` procedure blindly. The repository includes `Linux-mac-install.md`, `build-linux.sh` and `Dockerfile-msphpsql`, but the README does not provide a short, complete installation sequence for them.

Success should be evaluated at two layers. First, confirm that PHP loads the selected extension. Second, use the matching repository sample against the intended SQL Server or Azure SQL DB deployment and observe whether the connection succeeds. This separates extension-loading errors from database, credential, network or server configuration errors.

## Compatibility Constraints Across PHP, ODBC and SQL Server

Compatibility is broader than installing a DLL or PECL package. The client must use one of the listed PHP lines, 8.3.x, 8.4.x or 8.5.x, and Microsoft ODBC Driver 18 or 17 must be installed. A web server such as IIS or Apache must also be configured to run PHP. Failure to satisfy any of those conditions can occur before application query logic is reached.

Windows and Linux have different SQL Server floors. The documented server support starts with SQL Server 2012 on Windows and SQL Server 2016 on Linux. Binary selection adds another constraint: the PHP build's thread-safety mode and bitness must align with the runtime. Selecting a mismatched precompiled extension is therefore an installation risk, not a cosmetic packaging choice.

Feature expectations should also remain narrow. The future plans list Azure Active Directory, Always Encrypted and broader SQL Server feature support as work items. The same caution applies to performance: improvement is listed as a goal, but the README provides no performance measurement that would justify an adoption claim.

For UNIX deployments, the README points to platform-specific Microsoft documentation rather than claiming one universal command sequence. For source builds, it points to `buildscripts/README.md` and an example build script. That split increases the number of environment details an adopter must verify, particularly when the production host differs from the development workstation.

## Release Maintenance, Versioning and the MIT License

The repository is not archived. Its last push was on 2026-10-06, so its maintenance status should be described from that dated activity rather than from popularity or repository presentation. Recent release history also includes v5.13.3 on 2026-08-07, v5.13.2 on 2026-07-29 and v5.13.1 on 2026-04-30. These dates show recent releases, but they do not establish compatibility with every production deployment on their own.

The project follows semantic versioning. Under the documented policy, MAJOR changes indicate incompatible API changes, MINOR changes add backward-compatible functionality and PATCH changes contain backward-compatible fixes. Pre-release identifiers use `beta` or `RC`, while PECL versions omit the hyphen because of PECL restrictions. Build metadata can follow a plus sign and does not affect precedence.

This versioning scheme helps operators reason about upgrade boundaries, although they still need to check the release notes for current limitations. Upgrading PHP, replacing Microsoft ODBC Driver 17 with 18, changing thread-safety configuration or rebuilding the extension can each affect the deployment environment. The repository's Windows binary variants, UNIX installation requirements and source build route make upgrade planning part of both application and host maintenance.

The repository is licensed under MIT. That identifies the license published with the project, but applying its terms to a particular deployment requires reviewing the actual `LICENSE` file and relevant obligations. No legal conclusion about compatibility, support or redistribution should be inferred beyond what the license label states.

## Why PDO Drivers Are the Different Design Choice

PDO drivers such as `PDO_SQLSRV` offer a different adoption route from the procedural `SQLSRV` extension. PDO_SQLSRV exposes SQL Server through PHP's PDO abstraction, which can align with applications already designed around PDO. SQLSRV instead exposes a direct procedural interface. The choice is therefore partly about how the PHP application is structured, not about two packages that the repository says are interchangeable in every detail.

Compared with code that uses PDO drivers for several database systems, msphpsql adds SQL Server-specific environment requirements, including the supported Microsoft ODBC Driver. Compared with a self-contained database abstraction that handles its own connectivity, msphpsql deliberately delegates low-level communication to ODBC. Its advantage is direct alignment with SQL Server and Azure SQL DB; its cost is a larger client configuration surface.

It is the wrong choice when deployment compatibility is unknown. A team that cannot commit to PHP 8.3 through 8.5, cannot install Microsoft ODBC Driver 17 or 18, or runs a Linux SQL Server older than the documented floor should stop at the requirements stage. A team already built around `PDO_SQLSRV` should still inspect the current limitations before assuming that every SQL Server feature is accessible through the abstraction.

## Conclusion

Adopt microsoft/msphpsql when PHP is the application runtime, SQL Server is the database target, and the deployment environment supports PHP 8.3, 8.4 or 8.5 plus Microsoft ODBC Driver 17 or 18. Do not choose it merely for a portable database abstraction or for an unsupported SQL Server version. Before adoption, verify the extension variant against the web server's thread-safety and architecture, confirm the required ODBC driver on the client, and check the applicable release notes for current limitations.

## FAQ

### What PHP versions does microsoft/msphpsql support?

The repository lists PHP 8.3.x, 8.4.x and 8.5.x as the client requirements for this release. This release is described as supporting PHP 8.3 and later.

### Which database connectivity driver does microsoft/msphpsql require?

Both SQLSRV and PDO_SQLSRV rely on Microsoft ODBC Driver for SQL Server for low-level communication. The stated client prerequisite is Microsoft ODBC Driver 18 or 17.

### How do I enable the Microsoft PHP SQL Server drivers on Windows?

Place the selected DLL in the PHP extension directory, then add the applicable `extension=php_sqlsrv.dll` or `extension=php_pdo_sqlsrv.dll` entry to `php.ini`. Restart the web server after changing the configuration when PHP is running under a web server.

## Sources

- [Issues](https://github.com/microsoft/msphpsql/issues)
- [License: MIT](https://github.com/microsoft/msphpsql/blob/dev/LICENSE)
- [microsoft/msphpsql on GitHub](https://github.com/microsoft/msphpsql)
- [README](https://github.com/microsoft/msphpsql/blob/dev/README.md)
- [Releases](https://github.com/microsoft/msphpsql/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/microsoft-msphpsql
