PHP 5.3.27 access to Sql2008 and SQL 2005

Source: Internet
Author: User
Tags sql 2008 sql server driver mssql vc9

Today encountered the PHP connection MSSQL problem, in accordance with various attempts on the Internet, the final success, and then this record. Since PHP 5.3 does not support MSSQL. To download the appropriate SQL Server Driver for PHP. Now the Microsoft Official website has two installs the package: SQLSRV20.exe and SQLSRV30.exe

The following two installation packages, 20 are:

Driver file

PHP version

Thread safe?

Use with PHP. dll

Php_sqlsrv_53_nts_vc6.dll

Php_pdo_sqlsrv_53_nts_vc6.dll

5.3

No

Php5.dll

Php_sqlsrv_53_nts_vc9.dll

Php_pdo_sqlsrv_53_nts_vc9.dll

5.3

No

Php5.dll

Php_sqlsrv_53_ts_vc6.dll

Php_pdo_sqlsrv_53_ts_vc6.dll

5.3

Yes

Php5ts.dll

Php_sqlsrv_53_ts_vc9.dll

Php_pdo_sqlsrv_53_ts_vc9.dll

5.3

Yes

Php5ts.dll

Php_sqlsrv_52_nts_vc6.dll

Php_pdo_sqlsrv_52_nts_vc6.dll

5.2

No

Php5.dll

Php_sqlsrv_52_ts_vc6.dll

Php_pdo_sqlsrv_52_ts_vc6.dll

5.2

Yes

Php5ts.dll

30 are:

Driver file

PHP version

Thread safe?

Use with PHP. dll

Php_sqlsrv_53_nts.dll

Php_pdo_sqlsrv_53_nts.dll

5.3

No

Php5.dll

Php_sqlsrv_53_ts.dll

Php_pdo_sqlsrv_53_ts.dll

5.3

Yes

Php5ts.dll

Php_sqlsrv_54_nts.dll

Php_pdo_sqlsrv_54_nts.dll

5.4

No

Php5.dll

Php_sqlsrv_54_ts.dll

Php_pdo_sqlsrv_54_ts.dll

5.4

Yes

Php5ts.dll

Where 52 corresponds to the php5.2, VC9 corresponds to the format of your PHP package, for example (Php-5.3.27-win32-vc9-x86.zip). TS and nts The difference everyone should know, but also to your PHP version to correspond.

It is also important to note that if you download the corresponding PHP diver is 30.exe, then you have to install Microsoft SQL Server Native Client at the same time.

    • Version 3.0 of the driver requires Microsoft SQL Server Native Client. You can download Microsoft SQL Server Native Client from Thesql Server, Feature Pack page.

    • Version 2.0 of the driver requires Microsoft SQL Server R2 Native Client. Click on the appropriate link below:

      Download the X86 Package

      Download the X64 Package

Unzip the SQL Driver package and put it in the PHP directory while adding

Extension=php_pdo_mssql.dll
Extension=php_pdo_sqlsrv_53_ts_vc9.dll
Extension=php_sqlsrv_53_ts_vc9.dll
Extension=ntwdblib.dll

This is another important DLL file is the Ntwdblib.dll file, you can download the corresponding SQL version, each version is different, csdn on the download

SQL 2005 corresponds to number 2000.80.194.0,sql 2008 for number 2000.80.2039.0.

Download the Ntwdblib.dll in the PHP directory or directly under System32.

Restart the Apache server, Php.info display the following interface:

Indicates that the SQL configuration was successful.

Here is the test method:

    • <?php

    • $serverName = "(localhost)";

    • $connectionInfo =array ("Database" = "DbName", "UID" = "user", "pwd" = "pwd");

    • $conn =sqlsrv_connect ($serverName, $connectionInfo);

    • if ($conn) {

    • echo "Connection succeeded .<br/>";

    • }else{

    • echo "Connection failed .<br/>";

    • Die (Print_r (Sqlsrv_errors (), true));

    • }

      • ?>

PHP 5.3.27 access to Sql2008 and SQL 2005

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.