Code for connecting mssql2005 under PHP

Source: Internet
Author: User
Tags array echo date thread
1. Download the following two files, into the PHP ext directory and System32
Php_sqlsrv_52_ts_vc6.dll (thread safe)
Php_sqlsrv_52_nts_vc6.dll (not thread safe)
VC6 for APACHE,VC9 for IIS
2. Modify PHP.ini
Extension=php_sqlsrv_52_ts_vc6.dll
3. Download Sqlncli.msi, Microsoft Official can be under
The prompt for installation is SQL Server 2008, but 2005 is also available.
4. Test code
Copy CodeThe code is as follows:
<?php
$serverName = "127.0.0.1";
$connectionInfo = Array ("Database" => "TestDB", "UID" => "Test", "PWD" => "test");
$conn = Sqlsrv_connect ($serverName, $connectionInfo);
if ($conn) {
echo "Connection established.<br>";
} else {
echo "Connection could not to 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 ']. <br> ";
}
Sqlsrv_close ($conn);
echo "<br> done <br>";
echo Date ("y-m-d h:i:s");
?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.