ibmi/mapepire
Composer 安装命令:
composer require ibmi/mapepire
包简介
mapepire-php is a PHP client for the Mapepire database access layer for Db2 on IBM i.
README 文档
README
mapepire-php is a PHP client for the Mapepire database access layer for Db2 on IBM i.
⚠️ (WIP!) This Project is a work in progress, more features are coming
Summary
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
Installation
From the repository
- 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.
From Composer
- To be implemented
Usage
Connecting to the Server
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
Connecting with an associative array
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);
Connecting with a DaemonServer object
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);
Connecting with a .ini file
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");
Connecting with .connect()
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);
Authentication Information
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.
Getting a response
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.
Querying the Server
A Query object can be used to build a query and send it to a server. This is done through SQLJob's query() method:
require_once('vendor/autoload.php');
use Mapepire\SQLJob;
use Mapepire\Query;
$sqlJob = new SQLJob("/path/to/file/Mapepire.ini");
$query = $sqljob->query("select * from sample.employee");
$result = $query->run(rows: 1);
print_r($result);
Alternatively, SQLJob's queryAndRun() method can be used:
require_once('vendor/autoload.php');
use Mapepire\SQLJob;
$sqlJob = new SQLJob("/path/to/file/Mapepire.ini");
$result = $sqljob->queryAndRun("select * from sample.employee", rows: 1);
print_r($result);
Both implementations above code will result in the following output:
Array
(
[id] => query3
[has_results] => 1
[update_count] => -1
[metadata] => Array
(
[column_count] => 14
[job] => 325440/QUSER/QZDASOINIT
[columns] => Array
(
[0] => Array
(
[name] => EMPNO
[type] => CHAR
[display_size] => 6
[label] => EMPNO
[precision] => 6
[scale] => 0
)
[1] => Array
(
[name] => FIRSTNME
[type] => VARCHAR
[display_size] => 12
[label] => FIRSTNME
[precision] => 12
[scale] => 0
)
[2] => Array
(
[name] => MIDINIT
[type] => CHAR
[display_size] => 1
[label] => MIDINIT
[precision] => 1
[scale] => 0
)
[3] => Array
(
[name] => LASTNAME
[type] => VARCHAR
[display_size] => 15
[label] => LASTNAME
[precision] => 15
[scale] => 0
)
[4] => Array
(
[name] => WORKDEPT
[type] => CHAR
[display_size] => 3
[label] => WORKDEPT
[precision] => 3
[scale] => 0
)
[5] => Array
(
[name] => PHONENO
[type] => CHAR
[display_size] => 4
[label] => PHONENO
[precision] => 4
[scale] => 0
)
[6] => Array
(
[name] => HIREDATE
[type] => DATE
[display_size] => 10
[label] => HIREDATE
[precision] => 10
[scale] => 0
)
[7] => Array
(
[name] => JOB
[type] => CHAR
[display_size] => 8
[label] => JOB
[precision] => 8
[scale] => 0
)
[8] => Array
(
[name] => EDLEVEL
[type] => SMALLINT
[display_size] => 6
[label] => EDLEVEL
[precision] => 5
[scale] => 0
)
[9] => Array
(
[name] => SEX
[type] => CHAR
[display_size] => 1
[label] => SEX
[precision] => 1
[scale] => 0
)
[10] => Array
(
[name] => BIRTHDATE
[type] => DATE
[display_size] => 10
[label] => BIRTHDATE
[precision] => 10
[scale] => 0
)
[11] => Array
(
[name] => SALARY
[type] => DECIMAL
[display_size] => 11
[label] => SALARY
[precision] => 9
[scale] => 2
)
[12] => Array
(
[name] => BONUS
[type] => DECIMAL
[display_size] => 11
[label] => BONUS
[precision] => 9
[scale] => 2
)
[13] => Array
(
[name] => COMM
[type] => DECIMAL
[display_size] => 11
[label] => COMM
[precision] => 9
[scale] => 2
)
)
)
[data] => Array
(
[0] => Array
(
[EMPNO] => 000010
[FIRSTNME] => CHRISTINE
[MIDINIT] => I
[LASTNAME] => HAAS
[WORKDEPT] => A00
[PHONENO] => 3978
[HIREDATE] => 01/01/65
[JOB] => PRES
[EDLEVEL] => 18
[SEX] => F
[BIRTHDATE] =>
[SALARY] => 52750
[BONUS] => 1000
[COMM] => 4220
)
)
[is_done] =>
[success] => 1
[execution_time] => 185
)
The result is an associate array containing the metadata and data from the query. Here are the different fields returned:
* id field contains the query ID
* has_results field indicates whether the query returned any results
* update_count field indicates the number of rows updated by the query (-1 if the query did not update any rows)
* metadata field contains information about the columns returned by the query
* data field contains the results of the query
* is_done field indicates whether the query has finished executing
* success field indicates whether the query was successful.
* execution_time field indicates the time it took to execute the query
In the ouput above, the query was successful and returned one row of data.
Documentation
PHP Composer command composer doc will use phpDocumentor to generate the API documentation.
Tests
PHP Composer command composer test will run the test cases. Currently, the test cases are limited to instancing the classes. (WIP)
Asynchronous support
This will be coming.
ibmi/mapepire 适用场景与选型建议
ibmi/mapepire 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「db2」 「IBMi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ibmi/mapepire 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ibmi/mapepire 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ibmi/mapepire 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
The DreamFactory(tm) SQL DB Service.
Store your language lines in the database, yaml or other sources
laravel-ibmi is a simple DB2 & Toolkit for IBMi service provider for Laravel. It provides DB2 Connection by extending the Illuminate Database component of the laravel framework. Plus it also provides Toolkit for IBMi so that you can access IBMi resources with same credentials.
Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-08-14