PHP connection to SQL Server database library

Source: Internet
Author: User
Tags vc9

First look at your PHP version, PHP will no longer support the connection to SQL Server after 5.3, so it is necessary for MS to provide a third - party extension

Note: Although the Php_mssql.dll method provided by php5.2 is capable of connecting to a SQL Server Database (this connection is self-checking, online or more), it is only limited to SQL Server 2000. So if you need to connect to 2005 or more than 2008 versions, you still need to download the MS extension


ms extension download

Https://msdn.microsoft.com/en-us/library/cc296170.aspx

When downloading, pay attention to choose the corresponding PHP version number ( This is explained on the page )

Install the release program after download (the installation address to php.ini in the Extension_dir =), some of the following files are similar to:

Php_pdo_sqlsrv_52_nts.dll

Php_pdo_sqlsrv_52_ts.dll(for PHP 5.2.x version thread safe)

Php_sqlsrv_52_nts.dll

Php_sqlsrv_52_ts.dll(for PHP 5.2.x version thread safe)

Sqlserverdriverforphp.chm (Manual, English is good enough, can see)

Sqlserverdriverforphp_license.rtf

Sqlserverdriverforphp_readme.htm ( Readme file )

About the difference between VC6 and VC9

the VC6 version is compiled with the Visual Studio 6 compiler, and if you are using apache+php under Windows, select the VC6 version.

the VC9 version is compiled with the Visual Studio 2008 compiler, and if you are using iis+php under Windows , select the VC9 version.


Start configuration

1. Add the following php.ini Windows extensions:


Extension=php_sqlsrv_53_ts.dll (whichever file name you choose)

Extension=php_pdo_sqlsrv_53_ts.dll


2. Re-start Apache service.

Finally test whether the success, in PHP to perform phpinfo () view sqlsrv, look at the picture Red line, so that the connection is successful!!




Use the following code to test whether the connection was successful

<?php

$serverName = "(localhost)";

$connectionInfo = Array ("Database" = "test", "connectionpooling" =>false);

$conn = Sqlsrv_connect ($serverName, $connectionInfo);

if ($conn = = False)

{

echo "Connection failed! ";

die (Print_r (Sqlsrv_errors (), true) );

}

?>


In general, the operation will Error!

Reason: missing driver

Download page: https://msdn.microsoft.com/en-us/library/cc296170.aspx

In the page so a paragraph of words


My English slag, the general meaning is

Version 3.2 or 3.1 is required to download Microsoft ODBC Driver One-to-one for SQL Server.

3.0 version download SQL Server Feature Pack page.

Version 2.0 needs to be downloaded by the number of system bits:

Download the X86 Package

Download the X64 Package


After the download installation is complete, the OK program can be run.


Last Spit slot: PHP connection SQL Server It's just a pit-daddy, it's too much trouble.








PHP connection to SQL Server database library

Related Article

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.