文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>介绍几个windows下的COM相关函数

介绍几个windows下的COM相关函数

时间:2007-02-17  来源:PHP爱好者

本文介绍的函数只能在windows下的PHP中使用。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
函数列表:
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_load — 创建一个COM组件的引用。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_invoke — 调用一个COM组件的方法。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_propget — 取一个COM组件的属性的值。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_get — 同上,取一个COM组件的属性的值。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_propput — 赋一个值给一个COM组件的属性。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_propset — 同上,赋一个值给一个COM组件的属性。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_set — 同上,赋一个值给一个COM组件的属性。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
在www.php.net 下给出了如下实例:
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
例1:
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
<?
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$word=new COM("word.application") or die("Cannot start word for you");
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
print "Loaded word version ($word->Version)n";
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$word->visible =1 ;
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$word->Documents->Add();
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$word->Selection->Typetext("Dit is een test");
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$word->Documents[1]->SaveAs("burb ofzo.doc");
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$word->Quit();
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
?>
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
例2:
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
另外,有人给出了另一个例子,用 Delphi做了一个对象 MyObject (一个方法 ComTophp)。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
也可以这样用:
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$Obj = com_load("MyLibraryTest.MyObject");
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$result = com_invoke($Obj,"ComTophp","Params 1","Params 2");
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
echo $result;
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
上面这个例子我可没试过哦。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
例3:
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
<?
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
# example use of ADODB and SQLOLEDB (MS-SQL 7) in PHP 4
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
# Tested on Win2K with PHP 4.02
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$conn_obj = new COM("ADODB.Connection") or die("Cannot start ADO");
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
// replace myserver with your server name
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
define ("OLEDB_CONNECTION_STRING", "Provider=SQLOLEDB; Data Source=myserver; Initial Catalog=Northwind; User ID=sa; Password=");
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
// use SQL Server 7.0 OLE DB Provider
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$conn_obj->Open(OLEDB_CONNECTION_STRING);
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$command = "select lastname, firstname, title from employees"; // SQL Statement
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$rs = $conn_obj->Execute($command); // Recordset
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$i = 0;
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$fld0 = $rs->Fields(0);
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$fld1 = $rs->Fields(1);
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$fld2 = $rs->Fields(2);
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
while (!$rs->EOF) {
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$i += 1;
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
print "$fld0->value $fld1->value $fld2->value
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
";
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$rs->MoveNext();
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
}
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
$rs->Close();
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
?>
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
好了,下面就逐个介绍吧。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
//******************
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_load
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
(PHP3.0.3 - 3.0.16 only)
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
string com_load (string module name [, string server name])
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
创建一个COM组件新的引用,并返回它,如果失败,返回 false 。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
参数分别是模块名和服务器名。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
//********************
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_invoke
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
(PHP3.0.3 - 3.0.16 only, PHP4 )
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
mixed com_invoke (resource com_object, string function_name [, mixed function parameters, ...])
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
调用一个COM组件的方法。如果成功,返回function_name的返回值,否则,返回false。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
参数分别是:模块引用,方法名,方法所需的参数,
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
//*************************
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_propget
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
(PHP3.0.3 - 3.0.16 only, PHP4 )
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
mixed com_propget (resource com_object, string property)
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
取COM组件的一个属性的值,本函数是 com_get() 的一个别名。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
//*************************
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_get
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
(PHP3.0.3 - 3.0.16 only, PHP4 )
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
mixed com_get (resource com_object, string property)
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
参数分别是:COM引用,属性名。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
如果错误,返回 false。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
//***************************
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_propput
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
(PHP 3.0.3 - 3.0.16 only, PHP4 )
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
void com_propput (resource com_object, string property, mixed value)
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
给COM组件的一个属性付值。本函数是 com_set() 的一个别名。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
//****************************
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_propset
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
(PHP3.0.3 - 3.0.16 only, PHP4 )
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
void com_propset (resource com_object, string property, mixed value)
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
这也是com_set()的一个别名。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
//****************************
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
com_set
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
(PHP3.0.3 - 3.0.16 only, PHP4 )
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
void com_set (resource com_object, string property, mixed value)
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb

c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
给COM组件的一个属性赋值,参数是:组件模块名,属性名,新值。
c hina it power . c omtuGd5AyDYNsGP7tcOK9PQCqjb
如果错误,返回false,否则返回 true。
php爱 好者站 http://www.phpfans.net 文章|教程|下载|源码|论坛.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载