[转载]工作总结之PHP连接Microsoft SQL Server 2000/2005/2008

2013 年 11 月 25 日3720


    <?php

    $serverName = "(local)"; //数据库服务器地址

    $uid = "pandao"; //数据库用户名

    $pwd = "1987"; //数据库密码

    $connectionInfo = array("UID"=>$uid, "PWD"=>$pwd, "Database"=>"test");

    $conn = sqlsrv_connect( $serverName, $connectionInfo);

    if( $conn == false)

    {

    echo "连接失败!";

    die( print_r( sqlsrv_errors(), true));

    }

    $query = sqlsrv_query($conn, "SELECT TOP 10 nid,title,content FROM test.dbo.news");

    while($row = sqlsrv_fetch_array($query)){

    echo $row['nid']."-----".$row['title']."<br/>";

    }

    ?>

复制代码

0 0