mapepire-php is a PHP client for the Mapepire database access layer for Db2 on IBM i.
mapepire-php currently consists of two classes:
DaemonServer- a structure for initializing an SQLJob
SQLJob- the basic client which can connect, send a JSON request to the
mapepire-server, and receive a response
- the basic client which can connect, send a JSON request to the
- Clone the repository and use PHP Composer to do
composer installto download the component packages. - In your code
require_once('vendor/autoload.php');will pull in the component packages along withmapepire-phpclasses.
- To be implemented
There are four ways to instance 'SQLJob' and then connect:
- Passing in an associative array containing authentication information
- Passing in a
DaemonServerobject containing the authenication information - Passining in the path to a
.inifile listing the authenication information - Create an empty instance and call
SQLJob::connect()with one of the above passed in
The simplest and quickest way to connect to a server is to instance an SQLJob with a associative array as input:
Note: it is not recommended to set 'ignoreUnauthorized' to true in a live environment. See section on authentication information.
require_once('vendor/autoload.php');
use Mapepire\SQLJob;
$creds = [
'host' => "SERVER",
'user' => "USER",
'password' => "PASSWORD",
'ignoreUnauthorized' => true,
];
$connection = new SQLJob($creds);
A DaemonServer object can also be created in a similar fashion and passed in:
require_once('vendor/autoload.php');
use Mapepire\SQLJob;
use Mapepire\DaemonServer;
$ds = new DaemonServer(
host: "SERVER",
user: "USER",
password: "PASSWORD",
ignoreUnauthorized: true
);
$connection = newSQLJob($ds);
A path to a .ini file can be passed into SQLJob while creating an instance:
Mapepire.ini:
[mapepire]
SERVER="SERVER"
USER="USER"
PASSWORD="PASSWORD"
IGNOREUNAUTHORIZED="TRUE"
PHP:
require_once('vendor/autoload.php');
use Mapepire\SQLJob;
$connection = new SQLJob("/path/to/file/Mapepire.ini");
Optionally, you may specify a particular section of a .ini file by passing a second argument:
PHP:
require_once('vendor/autoload.php');
use Mapepire\SQLJob;
$connection = new SQLJob("/path/to/file/Mapepire.ini", "mapepire");
A connection can also be made after instancing SQLJob, for example with a DaemonServer object:
require_once('vendor/autoload.php');
use Mapepire\SQLJob;
use Mapepire\DaemonServer;
$ds = new DaemonServer(
host: "SERVER",
user: "USER",
password: "PASSWORD",
ignoreUnauthorized: true
);
$connection = newSQLJob();
$connection->connect($ds);
Regardless of connection method, the client performs authentication with information stored in a DaemonServer instance. The following may be passed for a connection:
- host (required) - the host name of the server
- username (required) - the user profile connecting to the server
- password (required) - the password of the user profile
- port (optional) - the server port, defaults to 8076
- ignoreUnauthorized (optional) - a boolean value determining whether to ignore if a user in unauthorized, defaults to false
- ca (optional) - the path to a certificate determining that a user is authorized. If (5) is false, this is required.
The response comes in the form of a phrity/websocket \WebSocket\Message\Text object.
Use the \WebSocket\Message\Text instance method getContent() to get the JSON message content.
You may further more use any other \WebSocket\Message\Text instance method on the response to examine the response and help debug your code.
This will be coming.
PHP Composer command composer doc will use phpDocumentor to generate the API documentation.
PHP Composer command composer test will run the test cases. Currently, the test cases are limited to instancing the classes. (WIP)
This will be coming.