Accessing U2 From PHP

From Pickwiki
Revision as of 23:48, 26 February 2015 by Conversion script (talk) (link fix)
Jump to navigationJump to search

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):

   $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
      $[[U2Error]] = $UOSession->Command->Error;
      $[[U2Status]] = $UOSession->Command->[[CommandStatus]];
      echo "Result is {$UOSession->Command->Response}";
      // may need to loop on $UOSession->Command->[[NextBlock]]
   $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)

A year ago 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.

   $Hostname = "";
   $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;

(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).


(from Rex Gozar)

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 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.