phpbar.de logo

Mailinglisten-Archive

[php] Zugriff auf DCOM-Objekte

[php] Zugriff auf DCOM-Objekte

Tobias Ratschiller tobias_(at)_dnet.it
Mon, 8 May 2000 13:37:50 +0200


> 1. direct auf die Objekte und Methoden der DCOM-Objekte (z.B. MS-Access)
> zuzugreifen? Ähnlich wie bei Perlscript

Aus dem Buch Web Application Development With PHP, das am 22. Juni bei New
Riders erscheint:
Invoking (D)COM controls with PHP 4 is very easy. COM is a reserved class
name that you can instantiate by passing the control's name to the
constructor. You then have a complete instance of the COM object where you
can execute functions or set and read properties as if it were a PHP class.
For properties that can't be expressed using PHP syntax (for example,
because they contain a dot or other characters invalid for PHP), you can use
the following helper functions:


bool com_set (class com_object, string property_name, string
property_value);
Assigns a value for a property on the
  COM object instantiated in com_object. Aliases for this function
  are com_propset() and com_propput().
  Returns true on success and false on
  error.


mixed com_get (class com_object, string property_name);
Returns the value of a property on the
  COM object instantiated in com_object. Alias for this function
  is com_propget(). Returns the property's value on success
  and false on error.

The source code in Listing 5.4 shows the basic use of the COM feature. It
creates an instance of the COM class using the Softwing.EDConverter
component, a freely available currency-conversion utility. Then the member
method Triangulate() is invoked and the returned result displayed. It can't
get much easier...

Figure 1. Listing 5.4. A basic COM example
$amount = 1000;         // Amount to be converted
$curr_from = "DEM";     // ISO currency symbol of original currency
$curr_to = "ITL";       // Symbol of the target currency

// Instantiate new COM object
$conv = new COM("Softwing.EDConverter") or die("Unable to instantiate
Euro-Converter");

// Execute a component method on the COM object's instance
$ret = $conv->Triangulate(10000, "ITL", "DEM") or die("Exception triggered
by Triangulate() on line ".__LINE__);

// Print the result
print($ret);
TIP
To create an instance of a DCOM component on a remote system, pass the
hostname as second argument to the constructor. For example:

$comp = new COM("My.Component", "remote.server.com");

Mit freundlichen Grüßen,  Tobias Ratschiller--
<?$c=$s=0;$a=$t=$x=$y=$b=-2;for(;$b-=$a>2?0.1/($a=-2):0,$b<2;$s.=chr(30+$c),
$a+=0.0503)for($x=  /* Tobias Ratschiller
*/$y=$c=0;++$c<90&$x*$x+$y*$y<4;$y=  /* http://phpWizard.net
*/2*$x*$y+$b,$x=$t)$t=$x*$x-$y*$y+$a;print(chunk_split($s,80));?>




php::bar PHP Wiki   -   Listenarchive