|
COM (no version information, might be only in CVS) COM -- COM 類 大綱$obj = new COM("server.object") |
描述
COM 類提供了一個將 (D)COM 元件整合到 PHP 腳本中的框架。
方法string COM::COM ( string module_name [, string server_name [, int codepage]] )
COM 類構造函數。參數:
- module_name
被請求元件的名字或 class-id。
- server_name
DCOM 伺服器的名字,元件在此伺服器上被取用。若果是
NULL,則假定是 localhost。想要容許
DCOM,必須將 php.ini 中的 com.allow_dcom
設為 TRUE。
- codepage
指定用於將 PHP 字串(php-strings)轉換成
UNICODE 字串(unicode-strings)的字碼頁,反之亦然。可用的值為
CP_ACP、CP_MACCP、CP_OEMCP、CP_SYMBOL、CP_THREAD_ACP, CP_UTF7
和 CP_UTF8。
例子 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;
|
|
例子 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;
|
|
| |