UsingCOMwithPHP(我就不翻译了)_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

";

$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. 本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉 本文系统来源:php中文网

a recordset php,UsingCOMwithPHP(我就不翻译了)_PHP相关推荐

  1. 《UniDAC 基础》 【菜头】 翻译 (之一)

    UniDAC快速入门 菜头  译 原文是在UniDAC的安装目录下,我复制了一份到我的博客里:点我 · Ø  简介   Ø  译者概述 Ø  连接到数据库 Ø  查询数据 Ø  执行查询 Ø  修改数 ...

  2. 最全程序员常用术语,科技互联网翻译必备

    最全程序员常用术语,科技互联网翻译必备 (整理不易,给个赞叭 蟹蟹) A abstract 抽象的 abstract base class (ABC)抽象基类 abstract class 抽象类 a ...

  3. JAVA英文翻译表--IT术语中英对照

    2008年02月15日 星期五 15:52 JAVA英文翻译表 ● 单词「式」: constructor 建构式 declaration 宣告式 definition 定义式 destructor 解 ...

  4. Mysql函数group_concat、find_in_set 多值分隔字符字段进行数据库字段值翻译

    Mysql函数group_concat.find_in_set进行数据库字段值翻译 场景 配方表:记录包含的原料 sources表示原料,字段值之间用逗号分隔 原料表:对应原料id和原料名称 现需要查 ...

  5. “Attention is All You Need 翻译

    <p><img src="output_0_0.png" alt="png"></p> "Attention is ...

  6. 基于PyTorch的Seq2Seq翻译模型详细注释介绍(一)

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qysh123/article/deta ...

  7. 全文翻译(全文合集):TVM: An Automated End-to-End Optimizing Compiler for Deep Learning

    全文翻译(全文合集):TVM: An Automated End-to-End Optimizing Compiler for Deep Learning 摘要 人们越来越需要将机器学习应用到各种各样 ...

  8. 全文翻译(四) TVM An Automated End-to-End Optimizing Compiler

    全文翻译(四) TVM An Automated End-to-End Optimizing Compiler 6.3 嵌入式GPU评估 对于移动GPU实验,在配备ARM Mali-T860MP4 G ...

  9. 全文翻译(三) TVM An Automated End-to-End Optimizing Compiler

    全文翻译(三) TVM An Automated End-to-End Optimizing Compiler 5. 自动化优化 考虑到一组丰富的调度原语,剩下的问题是为DL模型的每一层,找到最佳的算 ...

最新文章

  1. 常用的stsadm命令行参数
  2. Intellij 如何在新窗口中打开项目
  3. 调用反射类的指定方法
  4. 如何做到 jQuery-free?
  5. C++笔记(1):使用STL中sort()对struct排序
  6. C#.NET如何将cs文件编译成dll文件 exe文件 如何调用dll文件
  7. java 使用Sql数据库代码
  8. DST(对话状态追踪)常用方法
  9. java实现微信与支付宝支付使用同一二维码
  10. Java查看某个类的帮助文档
  11. Win11下载速度慢怎么办?Win11下载速度慢的解决方法
  12. 成功解决RecursionError: maximum recursion depth exceeded
  13. 树莓派自定义游戏,Minecraft硬件编程,建造房屋,我的世界还可以这样玩
  14. birt 报表与润乾报表对比
  15. 急诊与灾难医学-重点以及习题
  16. 在打破传统保险业的“玻璃屋顶” 之前,AI+保险还需跨过几道坎
  17. 电子信息工程专业概论_电子信息工程专业介绍
  18. 工程电磁场导论第三章总结
  19. html从零开始——为网页加入樱花飘落效果
  20. 基于RabbitMQ 的 Web MQTT插件进行前端消息实时推送

热门文章

  1. PL/SQL Developer SQL Window中不能插入多条数据
  2. Oracle系列:Oracle RAC集群体系结构
  3. 略论bs架构设计的几种模式
  4. 面试官系统精讲Java源码及大厂真题 - 34 只求问倒:连环相扣系列锁面试题
  5. Caddy - Web服务器的新秀 高性能 配置简单 动态代理 负载均衡
  6. Windows10 部署 Sonarqube 代码质量管理平台
  7. 分布式面试 - 为什么要进行系统拆分?
  8. Hystrix面试 - 深入 Hystrix 执行时内部原理
  9. 在CentOS上配置Percona XtraDB集群(Percona XtraDB Cluster)
  10. C#LeetCode刷题之#202-快乐数(Happy Number)