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.