Original: PHP connects to SQL Server 2008 database
With regard to PHP connection to SQL Server 2008, the 2000 version can be modified directly from the PHP configuration file, more than 2005 of the version will not be required to use the Microsoft Company provided driver (SQL Server Driver for PHP).
SQL Server Driver for PHP: http://www.microsoft.com/en-us/download/details.aspx?id=20098
1. Download the driver, install the release program after the download is complete, with the following files:
Php_pdo_sqlsrv_52_nts.dll
Php_pdo_sqlsrv_52_ts.dll
Php_pdo_sqlsrv_53_nts_vc6.dll
Php_pdo_sqlsrv_53_nts_vc9.dll
Php_pdo_sqlsrv_53_ts_vc6.dll
Php_pdo_sqlsrv_53_ts_vc9.dll
Php_sqlsrv_52_nts.dll
Php_sqlsrv_52_ts.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
Sqlserverdriverforphp.chm
Sqlserverdriverforphp_license.rtf
Sqlserverdriverforphp_readme.htm ( Readme file )
about the difference between VC6 and VC9
The VC6 version is compiled with the Visual Studio 6 compiler, and if you are using apache+php under Windows, select the VC6 version.
The VC9 version is compiled with the Visual Studio 2008 compiler, and if you are using iis+php under Windows, select the VC9 version.
This article PHP test environment: WAMP5 Environment Package;
1. Unzip the SQL Server driver for PHP driver into the Ext folder in the PHP file (because the computer system is XP, so download the 2.0 version).
2. After extensions in the configuration file php.ini file , add:
Extension=php_sqlsrv_53_ts.dll
Extension=php_pdo_sqlsrv_53_ts.dll
Note: This should be based on your PHP version of the original, if your version is 5.2 is the input
Extension=php_sqlsrv_52_ts.dll
Extension=php_pdo_sqlsrv_52_ts.dll
3. Restart Apache Service
4. Finally test whether the success, in PHP to perform phpinfo () view sqlsrv, look at the picture Red line, so that the connection is successful!!
Test code:
<?PHP$serverName= "localhost";//Database server address$uid= "SA";//Database user name$pwd= "123456";//Database Password$connectionInfo=Array("UID" =$uid, "PWD" =$pwd, "Database" = "Hzf");$conn= Sqlsrv_connect ($serverName,$connectionInfo);if($conn==false){ Echo"Connection Failed! "; die(Print_r(Sqlsrv_errors (),true));}//Execute SQL statement with result set$query= Sqlsrv_query ($conn, "SELECT * from test_id"); while($row= Sqlsrv_fetch_array ($query)){Echo $row[0]. " <br/> ";}?>
Output Result:
The above method is for the php5.2 version, the remaining version has not been tried, I hope the novice friends a little Help
PHP connection to SQL Server 2008 database