php下使用以下代码连接并测试
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:
复制代码 代码如下:
<?php
$myServer="localhost";//主机
$myUser="sa";//用户名
$myPass="password";//密码
$myDB="Northwind";?//MSSQL库名
$s=@mssql_connect($myServer,$myUser,$myPass)
ordie("Couldn'tconnecttoSQLServeron$myServer");
$d=@mssql_select_db($myDB,$s)
ordie("Couldn'topendatabase$myDB");
$query="SELECTTitleOfCourtesy+''+FirstName+''+LastNameASEmployee";
$query.="FROMEmployees";
$query.="WHERECountry='USA'ANDLeft(HomePhone,5)='(206)'";
$result=mssql_query($query);
$numRows=mssql_num_rows($result);
echo"<h1>".$numRows."Row".($numRows==1?"":"s")."Returned</h1>";
while($row=mssql_fetch_array($result))
{
echo"<li>".$row["Employee"]."</li>";
}