The Pyrrho Database Management System

Malcolm Crowe, University of the West of Scotland

6.7 Using PHP

There is an extra class ScriptConnect in PyrrhoLink.dll which is very useful for use with the scripting language PHP. (This class is added as from version 0.4.1 of Pyrrho.)

PHP can be used for building web applications, and then the same considerations as in the last section apply for the user identity of the web server and ownership of the databases. Unfortunately there does not yet seem to be a good way for PHP to work with Mono as a web server extension.

6.7.1 Enabling PHP support under Windows

To enable PHP support for Pyrrho under Windows, an administrator needs to issue the following two commands from the folder that contains PyrrhoLink.dll:

gacutil –i PyrrhoLink.dll

regasm PyrrhoLink.dll –tlb:PyrrhoLink.tlb

You also need to ensure that com.allow_dcom is set to true in c:\Windows\Php.ini.

[COM]

; path to a file containing GUIDs, IIDs or filenames of files with TypeLibs

;com.typelib_file =

; allow Distributed-COM calls

com.allow_dcom = true

6.7.2 Connecting to a Pyrrho database

The following steps can be used to access Pyrrho databases from PHP:

To create a connection to a Pyrrho database:

$conn = new COM(“Pyrrho.ScriptConnect”);

$conn->ConnectionString = …;

$conn->Open();

6.7.3 Retrieving data from the database

Once a connection is open as above, an SQL statement can be sent to the database as follows

$rdr = $conn->Execute(…);

The result returned will be a ScriptReader in the case that the SQL statement returns data.

Then

$row = $rdr->Read();

can be used to return successive rows of the data as variant arrays. If there are no more rows then the value returned is ‑1 , which can be tested using is_int($row) :

$row = $rdr->Read();

while(!is_int($row))

{

      print($row[0].': '.$row[1].'<br/>');

      $row = $rdr->Read();

}

$rdr->Close(); should be called when the reader is no longer required.

$conn->Execute(…); can also be used for other types of SQL statements.