1. Software configuration
Win7 +wampserver2.2d-x32+sql Server R2 database, the PHP version in wamp2.2 is 5.3.10.
PHP environment can also be changed to Php+apache.
2. Support connection to MySQL server configuration
Prior to PHP version 5.3, there are php_mssql features that can be used, but 5.3 and later versions are not supported.
2.1, PHP connection MSSQL Setup (php5.3 previous version)
(1), open php.ini, will
Extension=php_mssql.dll the semicolon (;) in front of it, and then restart Apache. If not, take the 2nd step.
(2) Check your PHP installation directory under ext There is no php_mssql.dll exist, if not, from www.php.net re-download a PHP installation, to download the compressed package is the most complete.
If the Ext directory already has the Php_mssql.dll, then you need to open php.ini, find
Extension_dir = "./ext"
This sentence (or similar, not necessarily "./ext", Look for "Extension_dir"), then change "./ext" to the full path of the ext directory of your PHP installation directory, such as "C:/php/ext", or "C:/Program files /php/ext "So. Then restart Apache again. If it doesn't work, it may take the 3rd step.
(3) Copy the Ntwdblib.dll and Php_mssql.dll in the PHP directory to the system32 system directory, and then re-start Apache.
(4) Then you can connect the MSSQL and do some operation. The connection examples are as follows:
$conn =mssql_connect ("Instance name or server IP", "username", "password"),//test connection if ($conn) { echo "connection succeeded";}mssql_select_db ("Database name"); if ($row =mssql_fetch_array ($rs)) { print_r ($row);}
2.2, PHP connection sqlsrv (php5.3 and above version)
(1), download Microsoft Drivers for PHP for SQL Server, official: http://www.microsoft.com/en-us/download/details.aspx?id=20098 , I'm using SQLSRV2.0.
(2), unzip the downloaded file to copy the Php_pdo_sqlsrv_53_ts_vc9.dll file and the Php_sqlsrv_53_ts_vc9.dll file to the Ext folder in the PHP installation directory. There are different files used here depending on the version.
(3), add in php.ini
Extension=php_sqlsrv_53_ts_vc9.dll
Extension=php_pdo_sqlsrv_53_ts_vc9.dll
to a lot; After the Extension=***.dll statement, note that Extension_dir points to the correct location.
(4), restart Apache, and then access the Http://apache access address/? Phpinfo=1, the content in the image below appears, and the configuration is correct.
(5), write the test code, the test code is as follows:
<?phpheader ("content-type:text/html; Charset=utf-8 "); $serverName = "localhost"; Database server address $uid = "Foodcert"; Database user Name $pwd = "Foodcert"; Database Password $connectioninfo = array ("UID" = = $uid, "PWD" = = $pwd, "database" = "Foodcert"); $conn = Sqlsrv_connect ($ ServerName, $connectionInfo); if ($conn = = False) {echo ' Connection failed! ";d ie (Print_r (sqlsrv_errors (), True));} Else{echo "Connection is successful! ";} $query = sqlsrv_query ($conn, "SELECT * from database table"), while ($row = Sqlsrv_fetch_array ($query)) { print_r ($row);}? >
(6), after the completion of the test code will appear when the connection failed, because the SQL Server Nation client, the local client, to download the appropriate client, I am using Microsoft? SQL Server? Native Client,:
http://www.microsoft.com/zh-cn/download/details.aspx?id=29065,
(7), after the installation is complete, after restarting Apache, then access will be able to connect successfully.
(8), note: You must have a Ntwdblib.dll file in the folder where the php.ini file exists.
(9), add: If you want to know the version of the driver and the local client version, you can view the http://php.net/manual/en/ sqlsrv.requirements.php, in the content, the content is the PHP official website document content, above describes the detailed steps, must learn to go to the official website to read the English document, is very detailed. The function description also exists in the document.
3. Reference website:
(1), Http://zhidao.baidu.com/link?url=NAu7PxrF38OeuRzvdWxLbhPVPCHoh_JyJyp_ Kqtruniavxmbv4f5c7yjuzjk5t5s6ojdc1yql0enqjhrotc09_
(2), http://jingyan.baidu.com/article/cd4c2979ccb866756e6e60c5.html
(3), http://blog.sina.com.cn/s/blog_55d5b4eb0100h3k7.html
(4), http://blog.knowsky.com/204198.htm
PHP supports connecting to SQL Server databases