UniVerse
Accessing IBMs UniVerse from PHP
Copyright © 1998-2010 Nemesis][
At work we use IBMs (formerly Vmark/Ardent/Informix/Now IBM) UniVerse RDBMS running on NT. Our employees currently access it using terminal / "green screen" applications such as Termite, Dynamic Connect, MacWise and command line telnet. One of the companies long time goals has been to revamp the interface into something a bit more user friendly; specifically adding a web front end.
Building on a LAMP (Linux, Apache, MySQL and PHP) stack, I tried several methods such as U2pipe, ODBC and even modified the dbtcp package to use ADO instead of ODBC (basically writing my own custom windows server using ADO in Delphi). While each method "worked"; each had problems. Some didn't allow direct access to subroutines and others had threading / blocking issues.
After scouring over the PickWiki website and digging deeper I stumbled over the Accessing U2 From PHP page. It shows how to access UniVerse using the UniObjects COM object in PHP. So I started looking for a good WAMP (Windows, Apache, MySQL, PHP) stack. I found what I was looking for in a package called Vertrigo (or additionally you can try: WampServer or XAMPP for windows). The next step was to connect the database back end to launch subroutines and issue commands. To launch a command:
<?
// create COM object
$UdSession = new COM("UniObjects.unioaifctrl");
// fill in arguments needed for login
$UdSession->HostName = $Hostname;
$UdSession->AccountPath = $Accountpath;
$UdSession->UserName = $Username;
$UdSession->Password = $Password;
// attempt login
$UdSession->Connect();
// is session active?
if (!$UdSession->IsActive) {
// Execute a command
$UdSession->Command->Text = "COUNT VOC";
$UdSession->Command->Exec;
$U2Error = $UdSession->Command->Error;
$U2Status = $UdSession->Command->CommandStatus;
echo "Result: {$UdSession->Command->Response}";
// may need to loop on $UOSession->Command->NextBlock
$UdSession->Disconnect;
}
?>
However there are no examples on calling subroutines. So after looking a quite a few Visual Basic and ASP examples I was able to make it work. Hopefully this will help someone else who needs a "working example".
Example PICK basic subroutine:
SUBROUTINE TESTSUB(R)
R = R + R
RETURN
How to call it from PHP:
<?
// Call TESTSUB with 1 argument
$subr = $UdSession->Subroutine("TESTSUB",1);
$subr->SetArg(0,"1234");
$subr->Call;
echo "Result: {$subr->GetArg(0)}";
// Returns: 2468
?>
Of course you'll need to add error checking and handling to the code, but these simple examples should be enough to get the ball rolling.
Last Modified: 09:39 AM on Wednesday March 25th, 2009
Views: 441