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

时间:2016-07-21 15:52:41 来源:互联网 作者: 神秘的大神 字体:

复制代码 代码如下:


$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 "

" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned

";

while($row = mssql_fetch_array($result))
{
echo "
  • " . $row["Employee"] . "
  • ";
    }


    www.bkjia.com true http://www.bkjia.com/PHPjc/318889.html TechArticle 复制代码 代码如下: ?php $myServer="localhost";//主机 $myUser="sa";//用户名 $myPass="password";//密码 $myDB="Northwind";?//MSSQL库名 $s=@mssql_connect($myServer,$my...