选择显示字体大小

using com with php


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.


<?
&#36;dbc = new com(&quot;adodb.connection&quot;);
&#36;dbc->provider = &quot;msdasql&quot;;
&#36;dbc->open(&quot;nwind&quot;);
&#36;rs = &#36;dbc->execute(&quot;select * from products&quot;);
&#36;i = 0;
&#36;fld0 = &#36;rs->fields(0);
&#36;fld1 = &#36;rs->fields(1);
&#36;fld2 = &#36;rs->fields(2);
while (!&#36;rs->eof) {
&#36;i += 1;
print &quot;&#36;fld0->value &#36;fld1->value &#36;fld2->value<br>&quot;;
&#36;rs->movenext(); /*updates fld0, fld1, fld2 !*/
}
&#36;rs->close();
?>

the equivalent of php's print &#36;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.

<?
&#36;word=new com(&quot;word.application&quot;) or die(&quot;cannot start ms word&quot;);
print &quot;loaded word version (&#36;word->version)\n&quot;;
&#36;word->visible = 1 ;
&#36;word->documents->add();
&#36;word->selection->typetext(&quot;this is a test&quot;);
?>

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.


<?
&#36;dbc = new com('adodb.connection');
&#36;dbc->provider = 'msdasql';
&#36;dbc->open('nwind'); // standard sample access database northwind
&#36;rs = new com(&quot;adodb.recordset&quot;);

/* the following line fails with an invoke error */
/* because we are passing &#36;dbc to &#36;rs */
&#36;rs->open('select * from product',&#36;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. 

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons