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; ";
// Access, such as: $ ado =" driver = {microsoft access driver (*.mdb)}; dbq = "." Mydb.mdb ");
$ DBC onn ->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" ->Close ;
$dbConn=null;
?>How about
, 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~
Accessing the stored procedures of SQL Server is almost the same as ASP. .
For more related content, you can follow php Chinese website (www.php.cn)!