📄 class.com.html
字号:
PHP string is passed as a parameter or returned from a method of this COM object. The code page is sticky in PHP 5, which means that it will propagate to objects and variants returned from the object. </span> <span class="simpara"> Possible values are <b><tt>CP_ACP</tt></b> (use system default ANSI code page - the default if this parameter is omitted), <b><tt>CP_MACCP</tt></b>, <b><tt>CP_OEMCP</tt></b>, <b><tt>CP_SYMBOL</tt></b>, <b><tt>CP_THREAD_ACP</tt></b> (use codepage/locale set for the current executing thread), <b><tt>CP_UTF7</tt></b> and <b><tt>CP_UTF8</tt></b>. You may also use the number for a given codepage; consult the Microsoft documentation for more details on codepages and their numeric values. </span> </dd> </dt> </dl> </p> </div> <div class="refsect1 unknown"> <h3 class="title">Overloaded Methods</h3> <p class="para"> The returned object is an overloaded object, which means that PHP does not see any fixed methods as it does with regular classes; instead, any property or method accesses are passed through to COM. </p> <p class="para"> Starting with PHP 5, PHP will automatically detect methods that accept parameters by reference, and will automatically convert regular PHP variables to a form that can be passed by reference. This means that you can call the method very naturally; you needn't go to any extra effort in your code. </p> <p class="para"> In PHP 4, to pass parameters by reference you need to create an instance of the <a href="class.variant.html" class="xref">VARIANT</a> class to wrap the byref parameters. </p> </div> <div class="refsect1 unknown"> <h3 class="title">Pseudo Methods</h3> <p class="para"> In PHP versions prior to 5, a number of not very pleasant hacks meant that the following method names were not passed through to COM and were handled directly by PHP. PHP 5 eliminates these things; read the details below to determine how to fix your scripts. These magic method names are case insensitive. </p> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><b><a href="function.com-addref.html" class="function">COM::AddRef</a></b></span> ( <span class="methodparam">void</span> )</div> <p class="simpara"> Artificially adds a reference count to the COM object. </p> <div class="warning"><b class="warning">Warning</b> <p class="simpara"> You should never need to use this method. It exists as a logical complement to the Release() method below. </p> </div> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><b><a href="function.com-release.html" class="function">COM::Release</a></b></span> ( <span class="methodparam">void</span> )</div> <p class="simpara"> Artificially removes a reference count from the COM object. </p> <div class="warning"><b class="warning">Warning</b> <p class="simpara"> You should never need to use this method. Its existence in PHP is a bug designed to work around a bug that keeps COM objects running longer than they should. </p> </div> </div> <div class="refsect1 unknown"> <h3 class="title">Pseudo Methods for Iterating</h3> <p class="para"> These pseudo methods are only available if <a href="function.com-isenum.html" class="function">com_isenum()</a> returns <b><tt>TRUE</tt></b>, in which case, they hide any methods with the same names that might otherwise be provided by the COM object. These methods have all been eliminated in PHP 5, and you should use <a href="com.examples.html" class="xref">Examples</a> instead. </p> <div class="methodsynopsis dc-description"> <span class="type"><a href="class.variant.html" class="type variant">variant</a></span> <span class="methodname"><b><b>COM::All</b></b></span> ( <span class="methodparam">void</span> )</div> <p class="simpara"> Returns a variant representing a SafeArray that has 10 elements; each element will be an empty/null variant. This function was supposed to return an array containing all the elements from the iterator, but was never completed. Do not use. </p> <div class="methodsynopsis dc-description"> <span class="type"><a href="class.variant.html" class="type variant">variant</a></span> <span class="methodname"><b><b>COM::Next</b></b></span> ( <span class="methodparam">void</span> )</div> <p class="simpara"> Returns a variant representing the next element available from the iterator, or <b><tt>FALSE</tt></b> when there are no more elements. </p> <div class="methodsynopsis dc-description"> <span class="type"><a href="class.variant.html" class="type variant">variant</a></span> <span class="methodname"><b><b>COM::Prev</b></b></span> ( <span class="methodparam">void</span> )</div> <p class="simpara">Returns a variant representing the previous element available from the iterator, or <b><tt>FALSE</tt></b> when there are no more elements. </p> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><b><b>COM::Reset</b></b></span> ( <span class="methodparam">void</span> )</div> <p class="simpara"> Rewinds the iterator back to the start. </p> </div> <div class="refsect1 unknown"> <h3 class="title">COM examples</h3> <p class="para"> <div class="example" id="example.com1" name="example.com1"> <p><b>Example #1 COM example (1)</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// starting word<br /></span><span style="color: #0000BB">$word </span><span style="color: #007700">= new </span><span style="color: #0000BB">COM</span><span style="color: #007700">(</span><span style="color: #DD0000">"word.application"</span><span style="color: #007700">) or die(</span><span style="color: #DD0000">"Unable to instantiate Word"</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Loaded Word, version {$word->Version}\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//bring it to front<br /></span><span style="color: #0000BB">$word</span><span style="color: #007700">-></span><span style="color: #0000BB">Visible </span><span style="color: #007700">= </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//open an empty document<br /></span><span style="color: #0000BB">$word</span><span style="color: #007700">-></span><span style="color: #0000BB">Documents</span><span style="color: #007700">-></span><span style="color: #0000BB">Add</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//do some weird stuff<br /></span><span style="color: #0000BB">$word</span><span style="color: #007700">-></span><span style="color: #0000BB">Selection</span><span style="color: #007700">-></span><span style="color: #0000BB">TypeText</span><span style="color: #007700">(</span><span style="color: #DD0000">"This is a test..."</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$word</span><span style="color: #007700">-></span><span style="color: #0000BB">Documents</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]-></span><span style="color: #0000BB">SaveAs</span><span style="color: #007700">(</span><span style="color: #DD0000">"Useless test.doc"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//closing word<br /></span><span style="color: #0000BB">$word</span><span style="color: #007700">-></span><span style="color: #0000BB">Quit</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//free the object<br /></span><span style="color: #0000BB">$word </span><span style="color: #007700">= </span><span style="color: #0000BB">null</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> <div class="example" id="example.com2" name="example.com2"> <p><b>Example #2 COM example (2)</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br />$conn </span><span style="color: #007700">= new </span><span style="color: #0000BB">COM</span><span style="color: #007700">(</span><span style="color: #DD0000">"ADODB.Connection"</span><span style="color: #007700">) or die(</span><span style="color: #DD0000">"Cannot start ADO"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">Open</span><span style="color: #007700">(</span><span style="color: #DD0000">"Provider=SQLOLEDB; Data Source=localhost;<br />Initial Catalog=database; User ID=user; Password=password"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$rs </span><span style="color: #007700">= </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">Execute</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT * FROM sometable"</span><span style="color: #007700">); </span><span style="color: #FF8000">// Recordset<br /><br /></span><span style="color: #0000BB">$num_columns </span><span style="color: #007700">= </span><span style="color: #0000BB">$rs</span><span style="color: #007700">-></span><span style="color: #0000BB">Fields</span><span style="color: #007700">-></span><span style="color: #0000BB">Count</span><span style="color: #007700">();<br />echo </span><span style="color: #0000BB">$num_columns </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />for (</span><span style="color: #0000BB">$i</span><span style="color: #007700">=</span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">< </span><span style="color: #0000BB">$num_columns</span><span style="color: #007700">; </span><span style="color: #0000BB">$i</span><span style="color: #007700">++) {<br /> </span><span style="color: #0000BB">$fld</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">] = </span><span style="color: #0000BB">$rs</span><span style="color: #007700">-></span><span style="color: #0000BB">Fields</span><span style="color: #007700">(</span><span style="color: #0000BB">$i</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$rowcount </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />while (!</span><span style="color: #0000BB">$rs</span><span style="color: #007700">-></span><span style="color: #0000BB">EOF</span><span style="color: #007700">) {<br /> for (</span><span style="color: #0000BB">$i</span><span style="color: #007700">=</span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">< </span><span style="color: #0000BB">$num_columns</span><span style="color: #007700">; </span><span style="color: #0000BB">$i</span><span style="color: #007700">++) {<br /> echo </span><span style="color: #0000BB">$fld</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]-></span><span style="color: #0000BB">value </span><span style="color: #007700">. </span><span style="color: #DD0000">"\t"</span><span style="color: #007700">;<br /> }<br /> echo </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$rowcount</span><span style="color: #007700">++; </span><span style="color: #FF8000">// increments rowcount<br /> </span><span style="color: #0000BB">$rs</span><span style="color: #007700">-></span><span style="color: #0000BB">MoveNext</span><span style="color: #007700">();<br />}<br /><br /></span><span style="color: #0000BB">$rs</span><span style="color: #007700">-></span><span style="color: #0000BB">Close</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">Close</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$rs </span><span style="color: #007700">= </span><span style="color: #0000BB">null</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">null</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.com.html">COM Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.dotnet.html">DOTNET</a></div> <div class="up"><a href="ref.com.html">COM Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -