usingcomwithphp (I will not translate) _php

Source: Internet
Author: User
Keywords Translation Is the com php of and to
Tags ole windows web server support microsoft
Using COM with PHP
by John Lim.

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

Here is some examples of stuff I have tried. Hope This gives you some ideas. Note that these is running PHP on a Windows Web server.


Active Data Objects (ADO) with PHP
ADO is Microsoft's database object technology. There is objects for connecting to databases, recordsets for data returned from queries, and Field objects representing D ATA elements.

Most databases don't support ADO directly. Instead most databases support 2 lower level Microsoft database Technologies:odbc and OLE DB. more databases support ODBC; But OLE DB has a reputation of being faster than ODBC.

ADO is then an API wrapper around ODBC and OLE DB.

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;
$FLD 0 = $rs->fields (0);
$FLD 1 = $rs->fields (1);
$FLD 2 = $rs->fields (2);
while (! $rs->eof) {
$i + = 1;
Print "$fld 0->value $fld 1->value $fld 2->value
";
$rs->movenext (); /*updates fld0, Fld1, Fld2!*/
}
$rs->close ();
?>

The equivalent of PHP ' s print $fld 0->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) are fields and default Propert Y of a Field element is value.

PHP does not support the default collections and properties, so we had 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 on the online help, but it's not in the default installation. Go to the MS Office installer, select VBScript documentation on options and you'll be ready to have some fun!


PHP COM Bugs
While testing ADO, I-hit this bug with PHP 4.02. It seems a 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, the data types null and currency is not supported.

3 Jan 2001:none of the above bugs has 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.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.