PHP uses COM objects to access SQL Server, Access

Source: Internet
Author: User
Keywords PHP uses COM objects to access SQL Server Access
php4.0.6 above can access COM and DCOM objects in the Win32 platform. Here to borrow the ASP idea to visit SQL Server. Of course you can also use the MSSQL series function. If it is an ASP coder, you will feel the following code very familiar, accustomed to----without him, but PHP Changl ~_~:
City: Zhengzhou

$dbConn =new COM ("ADODB. Connection ") or Die (" Create COM Failed ");
$ADO = "Provider=sqloledb;data source=localhost;initial catalog=mytest; User Id=sa; Password=sa; ";
Access such as: $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 (" Create RS failed ");
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;

$rs->movenext ();

$rs =null;

$dbConn =null;

How's that, easy? For ASP coder, if suddenly your boss received a PHP project list, you do not have to panic, spend a little time you can also successfully develop the ~

Accessing SQL Server's stored procedures is almost the same as ASP's practice.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.