Home>Article>Backend Development> Can php use sqlserver?

Can php use sqlserver?

(*-*)浩
(*-*)浩 Original
2019-09-24 13:12:58 4592browse

Can php use sqlserver?

Support connection to MySQL Server configuration

Before php version 5.3, there was a php_mssql function that can be used, but it is not supported in 5.3 and later versions. (Recommended learning:PHP programming from entry to proficiency)

php connection to sqlsrv (php5.3 and above)

(1), Download Microsoft Drivers for PHP for SQL Server, official download address: http://www.microsoft.com/en-us/download/details.aspx?id=20098, I am using SQLSRV2.0.

(2) Unzip the downloaded file and copy the php_pdo_sqlsrv_53_ts_vc9.dll file and php_sqlsrv_53_ts_vc9.dll file to the ext folder in the PHP installation directory. Different files are used here depending on the version.

(3). Add

extension=php_sqlsrv_53_ts_vc9.dll

extension=php_pdo_sqlsrv_53_ts_vc9.dll

to many;extension=* in php.ini After the **.dll statement, pay attention to whether the location pointed to by extension_dir is correct.

(4) Restart apache, and then visit http://apache access address/?Phpinfo=1. If the content of sqlsrv appears, it means the configuration is correct.

(5). Write the test code. The test code is as follows:

$uid, "PWD"=>$pwd, "Database"=>"FoodCert"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn == false) { echo "连接失败!"; die( print_r( sqlsrv_errors(), true)); }else{ echo "连接成功!"; } $query = sqlsrv_query($conn, "select * from 数据库表"); while($row = sqlsrv_fetch_array($query)) { print_r($row); } ?>

(6). After the above is completed, the connection will fail when testing the code because the sql server nation client is not installed. Local client, download the appropriate client. I am using Microsoft® SQL Server® 2012 Native Client.

(7). After the installation is completed, restart apache, and then access and the connection will be successful.

(8). Note: The ntwdblib.dll file must exist in the folder where the php.ini file is located.

The above is the detailed content of Can php use sqlserver?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn