Chinaunix首页 | 论坛 | 博客
  • 博客访问: 898957
  • 博文数量: 1812
  • 博客积分: 90800
  • 博客等级: 元帅
  • 技术积分: 22390
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-03 18:35
文章分类

全部博文(1812)

文章存档

2008年(1812)

我的朋友

分类:

2008-05-03 20:10:51

技术文章

WIN下比较简单:

1.安装SQL服务器并添加PHP的MSSQL扩展.(参见文章:win2000搭建PHP+Sql Server2000环境)

2.使用以下代码连接并测试


$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"] . "
  • "
    ;
    }

    ?>

    代码来源:PHP手册

    -------------------------------------------------

    LINUX下的方法如下:(以TCP/IP 远程连接MSSQL)

    1.安装freetds后.配置好.

    一般是这样:

    [MSSQL_2000]
    host = 192.168.0.25
    port = 1433
    tds version = 8.0

    2.编译PHP时.加上 --with-mssql=/freetbs的path

    3.连接测试:

    $msconnect=mssql_connect("MSSQL_2000","sa","");
    $msdb=mssql_select_db("Northwind",$msconnect);
    $msquery = "select titleofcourtesy,firstname,lastname from employees";
    $msresults= mssql_query($msquery);
    while (
    $row = mssql_fetch_array($msresults)) {
    echo
    "

  • " . $row['titleofcourtesy'] . " " . $row['firstname'] . " " . $row['lastname'] . "
  • \n";
    }
    ?>

    WIN下比较简单:

    1.安装SQL服务器并添加PHP的MSSQL扩展.(参见文章:win2000搭建PHP+Sql Server2000环境)

    2.使用以下代码连接并测试


    $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"] . "
  • "
    ;
    }

    ?>

    代码来源:PHP手册

    -------------------------------------------------

    LINUX下的方法如下:(以TCP/IP 远程连接MSSQL)

    1.安装freetds后.配置好.

    一般是这样:

    [MSSQL_2000]
    host = 192.168.0.25
    port = 1433
    tds version = 8.0

    2.编译PHP时.加上 --with-mssql=/freetbs的path

    3.连接测试:

    $msconnect=mssql_connect("MSSQL_2000","sa","");
    $msdb=mssql_select_db("Northwind",$msconnect);
    $msquery = "select titleofcourtesy,firstname,lastname from employees";
    $msresults= mssql_query($msquery);
    while (
    $row = mssql_fetch_array($msresults)) {
    echo
    "

  • " . $row['titleofcourtesy'] . " " . $row['firstname'] . " " . $row['lastname'] . "
  • \n";
    }
    ?>

    技术文章 WIN和LINUX下PHP连接mssql的方法.WIN和LINUX下PHP连接mssql的方法.WIN和LINUX下PHP连接mssql的方法.WIN和LINUX下PHP连接mssql的方法.WIN和LINUX下PHP连接mssql的方法.WIN和LINUX下PHP连接mssql的方法.WIN和LINUX下PHP连接mssql的方法.WIN和LINUX下PHP连接mssql的方法.WIN和LINUX下PHP连接mssql的方法.WIN和LINUX下PHP连接mssql的方法.WIN和LINUX下PHP连接mssql的方法.WIN和LINUX下PHP连接mssql的方法.
    阅读(244) | 评论(0) | 转发(0) |
    给主人留下些什么吧!~~