Home > Article > Backend Development > PHP uses COM objects to access SQLServer and Access_PHP tutorial
PHP4.0.6 and above can access COM and DCOM objects in the Win32 platform. Here we borrow ASP ideas to access SQL Server. Of course you can also use mssql series functions. If you are an ASP Coder, you will feel that the following code is very familiar, and you are used to it - nothing else, but PHP is strong~_~:
//Author: erquan
// Date: 2003-3-4
//City: Zhengzhou
$dbConn=new COM ("ADODB.Connection") or die("Failed to create COM");
$ADO=" Provider=sqloledb;Data Source=localhost;Initial Catalog=myTest;User Id=sa;Password=sa;";
DBQ=" . realpath("mydb.mdb");
$dbConn->open($ADO);
//if($dbConn) echo "create conn OK";
$rs= new COM("ADODB.RecordSet") or die("Create RS failed");
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"
";
🎜> $dbConn->Close;
$dbConn=null;
?>
How about it, it’s very simple, right? For ASP Coder, if your BOSS suddenly receives an order for a PHP project, you don’t have to panic. It will take you a while to develop smoothly~
Access to SQL Server’s stored procedures is also compatible with ASP The approach is almost the same.
http://www.bkjia.com/PHPjc/314819.html
www.bkjia.com
true