Home >Backend Development >PHP Tutorial >Code to connect mssql2005 under php_PHP tutorial

Code to connect mssql2005 under php_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:32:29859browse

1. Download the following two files and put them in the php ext directory and system32
php_sqlsrv_52_ts_vc6.dll (thread-safe)
php_sqlsrv_52_nts_vc6.dll (non-thread-safe)
vc6 is for Apache, vc9 is for IIS
2. Modify php.ini
extension=php_sqlsrv_52_ts_vc6.dll
3. Download sqlncli.msi, which is officially available from Microsoft.
When installed, it is prompted that it is for sql server 2008, but 2005 can also be used.
4. Test code

Copy code The code is as follows:

$serverName = " 127.0.0.1";
$connectionInfo = array("Database"=>"TestDB","UID"=>"test","PWD"=>"test");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if($conn) {
echo "Connection established.
";
} else {
echo "Connection could not be established.< ;br>";
die(print_r(sqlsrv_errors(), true));
exit();
}
$sql = "select * from T_Employee";
$result = sqlsrv_query($conn,$sql);
$data = array();
while($row=sqlsrv_fetch_array($result)) {
$data[] = $row;
}
foreach($data as $p) {
echo $p['Name']."
";
}
sqlsrv_close($conn);
echo "< br> Done
";
echo date("Y-m-d h:i:s");
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322822.htmlTechArticle1. Download the following two files and put them in the php ext directory and system32 php_sqlsrv_52_ts_vc6.dll (thread safe) php_sqlsrv_52_nts_vc6. dll (non-thread safe) vc6 is used for Apache, vc9 is used for IIS 2. Modify ph...
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