PHP Connection sqlserver2008 under Windows

Source: Internet
Author: User
Tags sql server driver

If you need to communicate with SQL Server you need to http://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.dll
Php_sqlsrv_52_ts_vc6.dll
Php_sqlsrv_53_nts_vc6.dll
Php_sqlsrv_53_nts_vc9.dll
Php_sqlsrv_53_ts_vc6.dll
Php_sqlsrv_53_ts_vc9.dll
Php_sqlsrv_license.rtf
Sqlserverdriverforphp.chm
Sqlserverdriverforphp_readme.htm

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
Service name of the local test
$serverName = "(127.0.0.1)";
Using SQL Server Authentication, the parameters are used in the form of an array, once the user name, password, database name
If you are using Windows authentication, you can remove the user name 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 being established.\n";
Die (Print_r (Sqlsrv_errors (), true));
}
?>
If the connection is unsuccessful, restart SQL Server and try again.

PHP Connection sqlserver2008 under Windows

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.