Difference between revisions of "Accessing U2 From PHP"

From Pickwiki
Jump to navigationJump to search
m (link fix)
m
Line 16: Line 16:
 
(from Brian Leach)
 
(from Brian Leach)
  
PHP has good support for Web Services, so you could surface some UDT
+
PHP has good support for Web Services, so you could surface some UDT functionality that way. There was also an article on <nowiki>DeveloperWorks</nowiki> on
functionality that way. There was also an article on <nowiki>DeveloperWorks</nowiki> on
+
creating a custom PHP module that exposed some of the [[InterCall]] library, though it was a long way from a complete solution.  
creating a custom PHP module that exposed some of the [[InterCall]] library,
 
though it was a long way from a complete solution.  
 
  
I also dimly remember someone writing an article on using a java bridge to
+
I also dimly remember someone writing an article on using a Java bridge to expose either RedBack objects or UOJ to PHP.
expose either <nowiki>RedBack</nowiki> objects or UOJ to PHP.
 
  
Some time ago I asked IBM whether they would be willing to publish the
+
Some time ago I asked IBM whether they would be willing to publish the UniObjects protocol so that third parties could write clients for those environments it doesn't support, like PHP - but that wasn't too well received and I didn't follow up on it. Instead, I wrote a web services library (before IBM released theirs) and tested that through with PHP's SOAP support.
<nowiki>UniObjects</nowiki> protocol so that third parties could write clients for those
 
environments it doesn't support, like PHP - but that wasn't too well
 
received and I didn't follow up on it. Instead, I wrote a web services
 
library (before IBM released theirs) and tested that through with PHP's SOAP
 
support.
 
  
 
== Using the PHP COM library ==
 
== Using the PHP COM library ==
 
(from Tony Gravagno)
 
(from Tony Gravagno)
  
With PHP5 you can just use the PHP COM library to access UO or UO.NET from
+
With PHP5 you can just use the PHP COM library to access UO or UO.NET from PHP directly.  It should be a LOT easier with PHP5 than PHP4.  Here's an example that I've created after a brief reference to the UO doc (haven't tried to execute):
PHP directly.  It should be a LOT easier with PHP5 than PHP4.  Here's an
+
 
example that I've created after a brief reference to the UO doc (haven't
 
tried to execute):
 
 
<pre>
 
<pre>
 
<?php
 
<?php
   $UOSession = new COM("[[UniObjects]].Unioiafctrl")
+
   $UOSession = new COM("UniObjects.Unioiafctrl")
 
       or die("Cant instantiate UO");
 
       or die("Cant instantiate UO");
   $UOSession->[[HostName]] = "yourhost";
+
   $UOSession->HostName = "yourhost";
   $UOSession->[[AccountPath]] = "d:\path\acct";
+
   $UOSession->AccountPath = "d:\path\acct";
   $UOSession->[[DatabaseType]] = 1; // UV here
+
   $UOSession->DatabaseType = 1; // UV here
   $UOSession->[[UserName]] = ""; // *nix only?
+
   $UOSession->UserName = ""; // *nix only?
 
   $UOSession->Password = ""; // *nix only?
 
   $UOSession->Password = ""; // *nix only?
 
   $UOSession->Connect; // need to check result
 
   $UOSession->Connect; // need to check result
   if ($UOSession->[[IsActive]]) {
+
   if ($UOSession->IsActive) {
 
       $UOSession->Command->Text = "COUNT VOC"; // whatever
 
       $UOSession->Command->Text = "COUNT VOC"; // whatever
 
       $UOSession->Command->Exec;
 
       $UOSession->Command->Exec;
       $[[U2Error]] = $UOSession->Command->Error;
+
       $U2Error = $UOSession->Command->Error;
       $[[U2Status]] = $UOSession->Command->[[CommandStatus]];
+
       $U2Status = $UOSession->Command->CommandStatus;
 
       echo "Result is {$UOSession->Command->Response}";
 
       echo "Result is {$UOSession->Command->Response}";
       // may need to loop on $UOSession->Command->[[NextBlock]]
+
       // may need to loop on $UOSession->Command->NextBlock
 
   }
 
   }
 
   $UOSession->Disconnect;
 
   $UOSession->Disconnect;
Line 61: Line 51:
 
</pre>
 
</pre>
  
This can do the same with UO.NET, mv.NET, and I'm guessing you can create
+
This can do the same with UO.NET, mv.NET, and I'm guessing you can create an ADODB.Connection with a DSN and make SQL queries as well - all of this only over Windows.  I believe FusionWare would have a similar Java-based solution for instantiating an object in PHP and accessing U2 entirely with <nowiki>*nix</nowiki>.
an ADODB.Connection with a DSN and make SQL queries as well - all of this
 
only over Windows.  I believe <nowiki>FusionWare</nowiki> would have a similar Java-based
 
solution for instantiating an object in PHP and accessing U2 entirely with
 
<nowiki>*nix</nowiki>.
 
  
 
----
 
----
 
(from Steve Morley)
 
(from Steve Morley)
  
A year ago I converted our Admin system to work from the web via php5.
+
I converted our Admin system to work from the web via PHP5.
 +
 
 +
Install UNIDK on the webserver and put the following code inside a PHP page. This will initiate the connection to the Unidata server and allow you to talk via UniObjects.
  
Install UNIDK on the webserver and put the following code inside a php page.
 
This will initiate the connection to the Unidata server and allow you to talk via <nowiki>UniObjects</nowiki>.
 
 
<pre>
 
<pre>
 
<?php
 
<?php
Line 80: Line 66:
 
   $Password = "password";
 
   $Password = "password";
 
   $Accountpath = "c:\ibm\mydemoaccount";
 
   $Accountpath = "c:\ibm\mydemoaccount";
   $[[UdSession]] = new COM("[[UniObjects]].unioaifctrl");
+
   $UdSession = new COM("UniObjects.unioaifctrl");
   $[[UdSession]]->[[HostName]] = $Hostname;
+
   $UdSession->HostName = $Hostname;
   $[[UdSession]]->[[AccountPath]] = $Accountpath;
+
   $UdSession->AccountPath = $Accountpath;
   $[[UdSession]]->[[UserName]] = $Username;
+
   $UdSession->UserName = $Username;
   $[[UdSession]]->Password = $Password;
+
   $UdSession->Password = $Password;
   $[[UdSession]]->Connect();
+
   $UdSession->Connect();
?>  
+
?>
 
</pre>
 
</pre>
  
Line 92: Line 78:
 
(from Brian Leach)
 
(from Brian Leach)
  
COM is windows-specific (which is why I didn't think to suggest it for
+
COM is windows-specific (which is why I didn't think to suggest it for PHP.) If you want to use UniObjects on Linux you'll need to use UOJ (Java version).
PHP.) If you want to use <nowiki>UniObjects</nowiki> on Linux you'll need to use UOJ (java
 
version).
 
  
 
== u2pipe ==
 
== u2pipe ==
Line 104: Line 88:
 
For our web application here, I created "web service subroutines" on the U2 backend, and wrote a PHP library of matching functions for the frontend to access them.  
 
For our web application here, I created "web service subroutines" on the U2 backend, and wrote a PHP library of matching functions for the frontend to access them.  
  
== Javascript and <nowiki>UniObjects</nowiki> ==
+
== Javascript and UniObjects ==
 
(Rick Brown)
 
(Rick Brown)
  
We wrote javascript that basically uses <nowiki>UniObjects</nowiki> to connect to Unidata and run a subroutine. We pass data back to the PHP program in XML format. The javascript is just used as the connector, one input and one output. We have a few different <nowiki>UniBasic</nowiki> subroutines that can be called, one even allows the PHP developer to send a series of sentences in ECL format and receive the results in XML. The javascript is maybe 18 lines, and we run it on Tomcat.
+
We wrote <nowiki>JavaScript</nowiki> that basically uses <nowiki>UniObjects</nowiki> to connect to Unidata and run a subroutine. We pass data back to the PHP program in XML format. The <nowiki>JavaScript</nowiki> is just used as the connector, one input and one output. We have a few different <nowiki>UniBasic</nowiki> subroutines that can be called, one even allows the PHP developer to send a series of sentences in ECL format and receive the results in XML. The <nowiki>JavaScript</nowiki> is maybe 18 lines, and we run it on Tomcat.
  
This works well for getting smaller data sets to the Web, not so great for hundreds of records. Our PHP developer simply takes the returned XML and throws it into an array.  With the same basic javascript we can pass the name of a subroutine to call, and provide input variables from PHP (Or pretty much any language with HTTP access)
+
This works well for getting smaller data sets to the Web, not so great for hundreds of records. Our PHP developer simply takes the returned XML and throws it into an array.  With the same basic <nowiki>JavaScript</nowiki> we can pass the name of a subroutine to call, and provide input variables from PHP (Or pretty much any language with HTTP access)
  
 
Using HTTP as our transport for the XML is kind of a kludge, but has opened a lot of information to our web developers.
 
Using HTTP as our transport for the XML is kind of a kludge, but has opened a lot of information to our web developers.

Revision as of 22:29, 15 May 2015

HowTos >> CreateWebInterfaces >> Accessing U2 from PHP

See also AccessFromPhp which includes other cross-platform ways to use PHP with MV. The techniques on this U2-specific page, and much of the code, can be used anywhere, and the code on the other page can augment solutions found here.

2008-01-14 from the u2ug users mailing list


Rocket Articles on U2 and PHP

(from David Wolverton)

Look at this page for several articles on PHP and U2:

PHP Web Services Strategy

(from Brian Leach)

PHP has good support for Web Services, so you could surface some UDT functionality that way. There was also an article on DeveloperWorks on creating a custom PHP module that exposed some of the InterCall library, though it was a long way from a complete solution.

I also dimly remember someone writing an article on using a Java bridge to expose either RedBack objects or UOJ to PHP.

Some time ago I asked IBM whether they would be willing to publish the UniObjects protocol so that third parties could write clients for those environments it doesn't support, like PHP - but that wasn't too well received and I didn't follow up on it. Instead, I wrote a web services library (before IBM released theirs) and tested that through with PHP's SOAP support.

Using the PHP COM library

(from Tony Gravagno)

With PHP5 you can just use the PHP COM library to access UO or UO.NET from PHP directly. It should be a LOT easier with PHP5 than PHP4. Here's an example that I've created after a brief reference to the UO doc (haven't tried to execute):

<?php
   $UOSession = new COM("UniObjects.Unioiafctrl")
      or die("Cant instantiate UO");
   $UOSession->HostName = "yourhost";
   $UOSession->AccountPath = "d:\path\acct";
   $UOSession->DatabaseType = 1; // UV here
   $UOSession->UserName = ""; // *nix only?
   $UOSession->Password = ""; // *nix only?
   $UOSession->Connect; // need to check result
   if ($UOSession->IsActive) {
      $UOSession->Command->Text = "COUNT VOC"; // whatever
      $UOSession->Command->Exec;
      $U2Error = $UOSession->Command->Error;
      $U2Status = $UOSession->Command->CommandStatus;
      echo "Result is {$UOSession->Command->Response}";
      // may need to loop on $UOSession->Command->NextBlock
   }
   $UOSession->Disconnect;
   $UOSession = null;
?>

This can do the same with UO.NET, mv.NET, and I'm guessing you can create an ADODB.Connection with a DSN and make SQL queries as well - all of this only over Windows. I believe FusionWare would have a similar Java-based solution for instantiating an object in PHP and accessing U2 entirely with *nix.


(from Steve Morley)

I converted our Admin system to work from the web via PHP5.

Install UNIDK on the webserver and put the following code inside a PHP page. This will initiate the connection to the Unidata server and allow you to talk via UniObjects.

<?php
   $Hostname = "192.168.0.1";
   $Username = "admin";
   $Password = "password";
   $Accountpath = "c:\ibm\mydemoaccount";
   $UdSession = new COM("UniObjects.unioaifctrl");
   $UdSession->HostName = $Hostname;
   $UdSession->AccountPath = $Accountpath;
   $UdSession->UserName = $Username;
   $UdSession->Password = $Password;
   $UdSession->Connect();
?>

(from Brian Leach)

COM is windows-specific (which is why I didn't think to suggest it for PHP.) If you want to use UniObjects on Linux you'll need to use UOJ (Java version).

u2pipe

(from Rex Gozar) http://www.autopower.com/rgozar/pixel.gif

I wrote u2pipe because I wanted (1) a single set of API subroutines on the U2 backend to handle all the business logic, and (2) to be able to port the API to different GUI clients (currently ColdFusion and PHP).

For our web application here, I created "web service subroutines" on the U2 backend, and wrote a PHP library of matching functions for the frontend to access them.

Javascript and UniObjects

(Rick Brown)

We wrote JavaScript that basically uses UniObjects to connect to Unidata and run a subroutine. We pass data back to the PHP program in XML format. The JavaScript is just used as the connector, one input and one output. We have a few different UniBasic subroutines that can be called, one even allows the PHP developer to send a series of sentences in ECL format and receive the results in XML. The JavaScript is maybe 18 lines, and we run it on Tomcat.

This works well for getting smaller data sets to the Web, not so great for hundreds of records. Our PHP developer simply takes the returned XML and throws it into an array. With the same basic JavaScript we can pass the name of a subroutine to call, and provide input variables from PHP (Or pretty much any language with HTTP access)

Using HTTP as our transport for the XML is kind of a kludge, but has opened a lot of information to our web developers.

Using U2 Web Development Environment (RedBack)

I wrote an object which allows full access to all the functionality in U2WDE from within PHP. This is a pure PHP script which requires no additional extensions to use. See https://github.com/gheydon/redback for the download and examples on how to use.

Getting PHP / Java / Universe (Unidata) to Work Together

PhpJavaIntegration: as PHP does not as of this date support the Universe database, this is one approach to get data into your PHP application.