仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1515|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网站制作之Using COM with PHP(我就不翻译了)

[复制链接]
简单生活 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:24:51 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
参加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.


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<BR>";
        $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.   建议大家买一本书,而不光是在网上看一些零碎的资料,一本书毕竟会讲的系统一些,全面一些,而且印刷的书不受电脑的限制,但是建议在看书的时候最好旁边有电脑,这样可以很及时地上机实践。
简单生活 该用户已被删除
沙发
 楼主| 发表于 2015-5-3 21:58:30 | 显示全部楼层
写js我最烦的就是 ie 和 firefox下同样的代码 结果显示的结果千差万别,还是就是最好不要用遨游去调试,因为有时候遨游是禁用js的,有可能代码是争取结果被遨游折腾的认为是代码写错。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-6-15 19:10

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表