× News Cego SysMT Croom Web Statistics Impressum
SysMT Logo
15   Using the PHP extension
Back to TOC

The cego PHP extension implements a plug-in for the PHP framework. This enables the PHP programmer to access a cego database with a PHP application. The following chapter descrbes the programming interface.

For using the PHP cego extension, you to compile a PHP distributing with enabled cego extension. Follow the detailed installation instructions of the corresponding PHP distribution.

15.1   Connecting to the database

To establish a connection to a running database, the cego_connect is used. The corresponding database server name, the database port, tableset and user information have to be provided with the function call.

<html>
<?
   print ("Connecting to database ...<br>");
   $db = cego_connect("localhost", 2200, "TS1", "lemke", "lemke");
   if ( $db == false ) die("Cannot connect to database : " . cego_error());
    ...


?>
</html>

As a result of the connect call, a database handle is returned in case of a successful connection establishment. Otherwise, false is returned and an error message is provided via cego_error().

15.2   Preparing a query

After a database connection has been established succesful, any queries can be prepared.

<html>
<?
    ...
    if ( $stmt = cego_prepare($db, "select a , b from t1;") == false)
    {
       print("Query error : " . cego_error());
    }
    ...

TODO

15.3   Executing a query

After prepration, the query can be executed.

<html>
<?
    ...
    if ( $fetchhandle = cego_execute($db, $stmt) == false)
    {
       print("Query error : " . cego_error());
    }
    ...

TODO

15.4   Tuple fetching

In case of select queries, a tuple result set must be retrieved. For this, a fetch handle has to be allocated using the cego_allocate_fetch function. The fetch handle is then provided to the cego_query function call. Using the fetch handle and an appropriate value array, the result tuples can be retrieved.


<html>
<?
    ...
     
    if ( $fetcharray = cego_fetch($fetchhandle) == false)
    {
       print("Query error : " . cego_error());
    }
    ...

    ...

    TODO
    ...

15.5   Parameter binding

For dynamic parameter binding, prepared statements can be used. A placeholder sign ? is used to indicate the paremter slots in the query. After the prepared statement has been created, the paramters can be binded using the cego_bind function.
To the bind call, a variable value of type CGVal with appropriate type and value information has to be provided.


    ...
    TODO
    ...

15.6   Function reference

A listing and description of all available API functions is given in the following.

Function Description
 string cego_phpversion();
Returns the installed cego PHP extension version.
 resource cego_connect(string hostname,
        int portno, 
        string tableset, 
        string user, 
        string pass);
Connect to the given database host, port and tableset with the corresponding user information.
 resource cego_prepare(string stmt);
Allocates a fetch handle, which can be used for select queries.
 bool cego_bind(resource stmt, string var, int type, int pos);
Frees an allocated fetch handle.
resource cego_execute(resource db, resource stmt);
Executes a prepared statement and returns a fetch handle.
bool cego_update (resource db, resource stmt);
Executes a prepared update statement. Returns true, if successful, else false
bool cego_query(resource db, string stmt);
Performs a plain query, given with the stmt string.
array cego_fetch(resource fetch);
Fetches next tuple from fetch resource. The tuple is provided in the array value that is returned.
array cego_fieldinfo(resource fetch);
Retrieves the attribute names of the selected query fields and returns the value array.
bool cego_release (resource fetch);
Releases an active fetch handle.
int cego_close (resource db);
Closes an active database resource.
string cego_error ();
Returns the last error stored in the global variable cgerrmsg