Home > Backend Development > PHP Tutorial > PHP利用COM对象访问SQLServer、Access_php基础

PHP利用COM对象访问SQLServer、Access_php基础

WBOY
Release: 2016-05-17 09:49:53
Original
1273 people have browsed it

PHP4.0.6以上可以在 Win32 平台中访问 COM 和 DCOM 对象。这里借用ASP思想访问一下SQLServer。当然你也可以用mssql系列函数。如果是一个ASP Coder,你会觉得下面代码非常眼熟,习惯----无他,但PHP强尔~_~:
//Author:    erquan
//Date:        2003-3-4
//City:郑州

    $dbConn=new COM ("ADODB.Connection") or die("创建COM失败");
    $ADO="Provider=sqloledb;Data Source=localhost;Initial Catalog=myTest;User Id=sa;Password=sa;";
         //Access如:$ADO="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("mydb.mdb");
    $dbConn->open($ADO);
    //if($dbConn) echo"create conn OK";
    $rs=new COM("ADODB.RecordSet") or die("创建RS失败");
    echo"
";
    //if($rs) echo"create rs OK";
    $sql="SELECT * FROM tb_bs";
    $rs->open($sql,$dbConn,1,1);

    while(!$rs->eof){

        echo $rs->fields["i_BsID"]->value.":";
        echo $rs->fields["vc_BsName"]->value;
        echo"
";

        $rs->movenext();
    }

    $rs->Close;
    $rs=null;

    $dbConn->Close;
    $dbConn=null;
?>

怎么样,很简单吧?对于ASP Coder,万一突然你的BOSS接到一个PHP项目的单子,你也不必惊慌,花一点时候你也可以顺利地进行开发了~

访问SQLServer的存储过程,也和ASP的做法几乎一样。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template