PHP Connect SQL Server steps in a detailed

Source: Internet
Author: User
Tags microsoft sql server php server

PHP connection to SQL Server encountered a lot of problems, here the detailed steps to record, for your reference:

First of all my is phpstudy-5.4, such as;

First step: Download sqlsrv

  Address:http://www.microsoft.com/en-us/download/details.aspx?id=20098

  Download is a self-extracting file, after decompression will have a bunch of DLL files

The second step: copy the corresponding PHP version of the DLL file to the PHP ext directory

  Version is php5.4, copy the Php_sqlsrv_54_ts.dll to the EXT directory

Step three: Modify the php.ini file

Add one line: Extension=php_sqlsrv_54_ts.dll

Modify one line: Mssql.secure_connection = Off to On

Fourth Step: Restart Apache

Fifth step: Install Microsoft SQL Server Native Client.msi

Install Microsoft SQL Server Native Client.msi, sub-X64 and X86 according to your system on the machine where the PHP server is located.

Http://www.softpedia.com/get/Internet/Servers/Server-Tools/SQL-Server-Native-Client.shtml

Sixth step: PHP code to determine whether the connection is successful

<?php
Header ("Content-type:text/html;charset=utf-8");
$conInfo =array (' Database ' = ' test ', ' UID ' = ' test ', ' PWD ' = ' 123456 ');

$conn =sqlsrv_connect (' 12.14.27.116 ', $conInfo);


/* Determine if the connection is successful or not: */

if (! $conn) echo "faild! connection error, user name password is not correct";
else echo "ok! can be connected";
?>

PHP Connect SQL Server steps in a detailed

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.