A PHP Database Composer Access Module.

Home Install Configure Database Manager Admin Schema Management Data Access Common Code Annex A - Database Manager API Annex B - Admin Manager API Annex C - Schema Manager API Annex D - Data Access API Annex E - Schema Driver API Annex F - Common API Download GitHub project Currently v0.5.0

© 2023. All rights reserved.

db-php A PHP Database Composer Access Module

Database Manager

Introduction

DBManager is the main interface to db-php and is the class that your application should call.

The API for the DBManager can be found at Annex A.

See the example code shown below for creating the class in your application:

try {
    $dbmanager = new \g7mzr\db\DBManager($dsn, $dsn["adminuser"], $dsn["adminpasswd"]);
} catch (Exception $ex) {
    echo $ex->getMessage();
    exit(1);
}

This example assumes that the RDMS superuser’s login details are part of the DSN. This need not be the case. The superuser’s login details are only needed to create a database user for the application and the blank database; they are not needed to run the application or maintain the database schema. It is up to you on how the administrator’s details are passed to DBManager.

Set Mode Function

Once you have successfully connected to DBManager you then need to select a function. This is when you connect to the database. There are three functions you can choose from:

  • admin - used to create and delete database users, and databases.
  • schema - used to add a schema to a blank database or update an existing one.
  • dataaccess - used to insert, update and delete records in the database.

To select the required function issue one of the following commands:

// Admin Function
$result = $dbmanager->setMode('admin');

// Schema Management Function
$result = $dbmanager->setMode('schema');

// Data Access Function
$result = $dbmanager->setMode('dataaccess');

If you have successfully connected to the database then $result will be true. If the command has failed then result will be an object of type \g7mzr\db\common\Error.

Access function

Once the mode has been set you can access the individual modules as follows:

Admin

The example below shows the admin module being used to check if a database user exists. Instructions for using the Admin Driver can be found here. The Admin Driver API can be found at Annex B.

$result = $dbmanager->getAdminDriver()->userExists("username");
if (\g7mzr\db\common\Common::isError($result)) {

    //Deal with error

}

Schema

The schema module is not accessed directly but via the schema manager. Instructions for using the schema Manager can be found here.

Data

The example below shows the DataDriver being used to obtain the Version of database being used by the application.Instructions for using the DataDriver can be found here. The DataDriver API can be found at Annex D.

$result = $dbmanager->getDataDriver()->getDBVersion();