john lim php,Using COM with PHP(我就不翻译了)_php

Using COM with php

By John Lim.

PHP4 on Windows has been extended to support Microsoft's COM technology. However documentation on the COM functions is very sparse at the moment.

Here are some examples of stuff I have tried. Hope this gives you some ideas. Note that these only work when you are running PHP on a Windows web server.

http://www.gaodaima.com/45432.htmlUsing COM with PHP(我就不翻译了)_php

Active Data Objects (ADO) with PHP

ADO is Microsoft's database object technology. There are objects for connecting to databases, recordsets for data returned from queries, and field objects representing data elements.

Most databases do not support ADO directly. Instead most databases support 2 lower level Microsoft database technologies: ODBC and OLEDB. More databases support ODBC; but OLEDB has a reputation of being faster than ODBC.

ADO is then an API wrapper around ODBC and OLEDB.

This example opens a new ADO Connection object, opens the traditional NorthWind MS-access database via ODBC. When we execute the SQL, a RecordSet object is returned. We then display the first 3 fields of the record-set.

$dbc = new COM("ADODB.Connection");

$dbc->Provider = "MSDASQL";

$dbc->Open("nwind");

$rs = $dbc->Execute("select * from products");

$i = 0;

$fld0 = $rs->Fields(0);

$fld1 = $rs->Fields(1);

$fld2 = $rs->Fields(2);

while (!$rs->EOF) {

$i += 1;

print "$fld0->value $fld1->value $fld2->value
";

$rs->MoveNext(); /*updates fld0, fld1, fld2 !*/

}

$rs->Close();

?>

The equivalent of PHP's print $fld0->value in VBScript is Response.Write( rs.Fields(0).value ); or more concisely Response.Write( rs(0) ) because the default collection of a recordset (rs) is Fields and default property of a Field element is value.

PHP does not support default collections and properties, so we have to write everything explicitly.

Invoking Microsoft Word with PHP

Here is another example.

$word=new COM("word.application") or die("Cannot start MS Word");

print "Loaded word version ($word->Version)/n";

$word->visible = 1 ;

$word->Documents->Add();

$word->Selection->Typetext("This is a test");

?>

Word's COM object model documentation is available in the online help, but it is not in the default installation. Go to the MS Office installer, select VBScript Documentation in options and you will be ready to have some fun!

PHP COM Bugs

While testing ADO, I hit this bug with PHP 4.02. It seems that passing a COM object as a parameter to a second COM object fails.

$dbc = new COM('ADODB.Connection');

$dbc->Provider = 'MSDASQL';

$dbc->Open('NWIND'); // standard sample access database northwind

$rs = new COM("ADODB.Recordset");

/* The following line fails with an INVOKE error */

/* because we are passing $dbc to $rs            */

$rs->Open('select * from product',$dbc,3); // 3 = static cursor

?>

Another bug is that the data types null and currency are not supported.

3 Jan 2001: None of the above bugs have been fixed in PHP 4.0.4. Do we have any COM C++ experts who could fix the bugs? PHP is open source after all.

欢迎大家阅读《Using COM with PHP(我就不翻译了)_php》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码

e7ce419cf2d6ad34d01da2ceb8829eed.png

微信 赏一包辣条吧~

023a57327877fb4402bcc76911ec18ea.png

支付宝 赏一听可乐吧~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值