How does PHP implement a connection to SQL Server2008 under the Windows platform?

Source: Internet
Author: User
This article mainly introduces the Windows platform to implement PHP connection SQL Server2008 method, combined with instance form analysis of the Windows platform PHP connection SQL Server2008 required DLL dynamic link library files and the corresponding configuration and use method, A friend you need can refer to the following

The example in this article describes how the Windows platform implements PHP connection SQL Server2008. Share to everyone for your reference, as follows:

If you need to communicate with SQL Server you need to msdn.microsoft.com/en-us/sqlserver/ff657782.aspx yourself to download Microsoft provided by the SQL Server Driver for PHP. This is a self-extracting file that will be extracted after extracting the following files:

Php_sqlsrv_52_nts_vc6.dllphp_sqlsrv_52_ts_vc6.dllphp_sqlsrv_53_nts_vc6.dllphp_sqlsrv_53_nts_vc9.dllphp_sqlsrv_ 53_ts_vc6.dllphp_sqlsrv_53_ts_vc9.dllphp_sqlsrv_license.rtfsqlserverdriverforphp.chmsqlserverdriverforphp_ Readme.htm


PS: The above compressed files can also be clicked here Download this site .

where 52,53 represents 5.2.X and 5.3.X versions of PHP, NTS represents non-line and security, TS is thread safe, VC6 means using Apache as a web server,vc9 means using IIS as a Web Server.

According to your configuration, copy the appropriate DLL files to the Ext folder of the PHP installation directory, then open php.ini and add the following statement to open the Php_sqlsrv and php_pdo_sqlsrv extensions:


—————————————————— –[php_pdo_sqlsrv]extension=php_pdo_sqlsrv_53_ts_vc6.dll[php_sqlsrv]extension=php_sqlsrv_53_ Ts_vc6.dll —————————————————

Here 53 is php5.3, if you are 5.2 version, change to 52, if your PHP version is thread-safe, then your PHP installation directory should have a php5ts.dll, and here the two lines corresponding to the statement, if it is Php5nts.dll, then the above statement should be:


—————————————————————-[php_pdo_sqlsrv]extension=php_pdo_sqlsrv_53_nts_vc6.dll[php_sqlsrv]extension=php_sqlsrv_ 53_nts_vc6.dll —————————————————-

There are various versions of the DLL files in the package, so you can check them carefully.

After opening the extension, restart Apache so that you can connect to SQL Server, but it is also important to note that if you do not have Microsoft SQL Server R2 Native Client installed, you must go to HTTP. The msdn.microsoft.com/en-us/library/cc296170 (sql.90). aspx download is installed because this support is required by Microsoft's Extension pack.

After everything is right, you can write PHP code, if you download the SQL Server Driver for PHP, then in the Unpacked folder there is a Help document, you can easily find the example, here the webmaster introduces a simple example:


<?php//Local Test Service name $servername = "(127.0.0.1)";//Use SQL Server Authentication, parameters using the form of an array, once is the user name, password, database name//If you are using Windows authentication, Then you can remove the username and password $connectioninfo = array ("UID" = "root", "PWD" = "Root2010″", "Database" = "master"); $conn = Sqlsrv_ Connect ($serverName, $connectionInfo), if ($conn) {echo "Connection established.\n";} Else{echo "Connection could not be established.\n";d ie (Print_r (sqlsrv_errors (), True));}? >

If the connection is unsuccessful, restart SQL Server and try again.

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.