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 in the form of examples. Friends in need You can refer to the following example
This article describes how to implement PHP connection to SQL Server2008 on the Windows platform. Share it with everyone for your reference, the details are as follows:
If you need to communicate with sql server, you need to download The SQL Server Driver for Microsoft provided by msdn.microsoft.com/en-us/sqlserver/ff657782.aspx PHP. This is a self-extracting file. After decompression, you will get 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
##PS:You can also click here to download the above compressed file.
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 —————————————————-
<?php //本地测试的服务名 $serverName = "(127.0.0.1)"; //使用sql server身份验证,参数使用数组的形式,一次是用户名,密码,数据库名 //如果你使用的是windows身份验证,那么可以去掉用户名和密码 $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"; die( print_r( sqlsrv_errors(), true)); } ?>
The above is the detailed content of How to connect php to SQL Server2008 under Windows platform?. For more information, please follow other related articles on the PHP Chinese website!