当前位置:首页 > PHP教程 > PHP基础知识

php下使用以下代码连接并测试

复制代码 代码如下:

<?php    

$myserver = "localhost"; //主机    
$myuser = "sa"; //用户名    
$mypass = "password"; //密码    
$mydb = "northwind";? //mssql库名    

$s = @mssql_connect($myserver, $myuser, $mypass)    
or die("couldn't connect to sql server on $myserver");    

$d = @mssql_select_db($mydb, $s)    
or die("couldn't open database $mydb");    

$query = "select titleofcourtesy+' '+firstname+' '+lastname as employee ";    
$query .= "from employees ";    
$query .= "where country='usa' and left(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>";    
}     



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!