(PHP 4 >= 4.1.0, PHP 5)
COM — COM 类
$obj = new COM("server.object")
COM 类提供了一个将 (D)COM 组件整合到 PHP 脚本中的框架。
COM 类构造函数。参数:
Example #1 COM 示例 (1)
// 启动 word
$word = new COM("word.application") or die("Unable to instanciate Word");
print "Loaded Word, version {$word->Version}\n";
//将其置前
$word->Visible = 1;
//打开一个空文档
$word->Documents->Add();
//随便做些事情
$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc");
//关闭 word
$word->Quit();
//释放对象
$word->Release();
$word = null;
Example #2 COM 示例 (2)
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$conn->Open("Provider=SQLOLEDB; Data Source=localhost;
Initial Catalog=database; User ID=user; Password=password");
$rs = $conn->Execute("SELECT * FROM sometable"); // 记录集
$num_columns = $rs->Fields->Count();
echo $num_columns . "\n";
for ($i=0; $i < $num_columns; $i++)
{
$fld[$i] = $rs->Fields($i);
}
$rowcount = 0;
while (!$rs->EOF)
{
for ($i=0; $i < $num_columns; $i++)
{
echo $fld[$i]->value . "\t";
}
echo "\n";
$rowcount++; // rowcount 自增
$rs->MoveNext();
}
$rs->Close();
$conn->Close();
$rs->Release();
$conn->Release();
$rs = null;
$conn = null;