PHP uses COM objects to access SQL Server, access_php basics

Source: Internet
Author: User
PHP4.0.6 above you can access COM and DCOM objects in the Win32 platform. Here borrow the ASP idea to visit SQL Server. Of course you can also use the MSSQL series functions. If it is an ASP coder, you will find the following code very familiar, habit----without him, but PHP Changl ~_~:
<?php
Author:erquan
Date:2003-3-4
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 ");
echo "<br>";
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 "<BR>";

$rs->movenext ();
}

$rs->close;
$rs =null;

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

How is it, it's easy? For ASP coder, if suddenly your boss received a list of PHP projects, you do not have to panic, spend a little time you can also successfully developed ~

Accessing SQL Server's stored procedures is almost the same as the ASP's approach.
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: info-contact@alibabacloud.com 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.