This article mainly introduces the method of connecting PHP to SQL Server 2008 on the Windows platform. It analyzes the relevant dll dynamic link library files and corresponding configuration and usage methods required for PHP to connect to SQL Server 2008 on the Windows platform. Friends in need can refer to the following. , hope it can help everyone.
If you need to communicate with sql server, you need to download The SQL Server Driver for PHP provided by Microsoft at http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx. This is a self-extracting file. After decompression, you will get the following files:
##php_sqlsrv_52_nts_vc6.dllphp_sqlsrv_52_ts_vc6.dll
php_sqlsrv_53_nts_vc6.dll
php_sqlsrv_53_nts_vc9.dll
php_sqls rv_53_ts_vc6 .dll
php_sqlsrv_53_ts_vc9.dll
php_sqlsrv_license.rtf
SQLServerDriverForPHP.chm
SQLServerDriverForPHP_Readme.htm
##PS:The above compressed files can also be downloaded from this site by clicking here.Among them, 52 and 53 represent the versions of PHP 5.2. Server.
According to your configuration, copy the corresponding DLL file to the ext folder of the PHP installation directory, then open php.ini and add the following statements 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 —————————————————
—————————————————————- [PHP_PDO_SQLSRV] extension=php_pdo_sqlsrv_53_nts_vc6.dll [PHP_SQLSRV] extension=php_sqlsrv_53_nts_vc6.dll —————————————————-
After turning on the extension, restart apache so that you can connect to sqlserver, but there is one more thing to note. If you have not installed Microsoft SQL Server 2008 R2 Native Client, you must go to http://msdn.microsoft.com Download and install /en-us/library/cc296170(SQL.90).aspx, because this extension package from Microsoft requires this support.
After everything is in place, you can write PHP code. If you downloaded The SQL Server Driver for PHP, there is a help document in the unzipped folder. You can easily find examples. Here the webmaster will introduce a simple example:
"root", "PWD"=>"root2010″, "Database"=>"master"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.\n"; } else { echo "Connection could not be established.\n"; die( print_r( sqlsrv_errors(), true)); } ?>
Related recommendations:
C#Example sharing of how to connect to sql server2008 database PHP 5.6.11 Several ways to access SQL Server2008R2 Detailed explanation of the situation_php example php56 is used in combination with sql server2008.The above is the detailed content of How to implement PHP connection to SQL Server2008 on Windows platform. For more information, please follow other related articles on the PHP Chinese website!