stefanak-michal/pdo-bolt
Composer 安装命令:
composer require stefanak-michal/pdo-bolt
包简介
PDO for Bolt protocol
README 文档
README
The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. This library is dedicated to add bolt protocol. This protocol was created by Neo4j and is used by graph databases like Neo4j, Memgraph or Amazon Neptune.
Right now there is no official C/C++ bolt driver and therefore it is not possible to make this library as extension. Even the unofficial driver looks like it is not maintained. Maybe in future it will change but before that you are welcomed to use this one.
Requirements
- PHP ^8
- Bolt library
Installation
You can use composer or download this repository from GitHub and manually implement it.
Composer
Run the following command in your project to install the latest applicable version of the package:
composer require stefanak-michal/pdo-bolt
Usage
You can use this library as typical PDO, but you have to create instance of \pdo_bolt\PDO which overrides \PDO and
adds bolt scheme.
$pdo = new \pdo_bolt\PDO('bolt:host=localhost;port=7687;appname=pdo-bolt', 'neo4j', 'neo4j'); $stmt = $pdo->prepare('RETURN $n AS num, $s AS str'); $stmt->bindValue('n', 123, \PDO::PARAM_INT); $stmt->bindValue('s', 'hello'); $stmt->execute(); $stmt->setFetchMode(\PDO::FETCH_ASSOC); foreach ($stmt AS $row) { print_r($row); } /* output: Array ( [num] => 123 [str] => hello ) */
For more information about how to use PDO follow official documentation at php.net.
DSN
| Key | Description |
|---|---|
| host | The hostname on which the database server resides. |
| port | The port number where the database server is listening. |
| dbname | The name of the database. |
| appname | The application name (used as UserAgent). |
PDO constructor available options
| Key | Description |
|---|---|
| auth | Specify authentication method (none/basic/bearer/kerberos). Automatically detected. |
| ssl | Enable encrypted communication and set ssl context options (see php.net) |
| protocol_versions | Specify requested bolt versions. Array of versions as int/float/string. |
Check method annotation for more informations.
Yii framework
You can use this library with Yii framework in very simple way. Just set up in configuration your PDO class.
https://www.yiiframework.com/doc/api/2.0/yii-db-connection#$pdoClass-detail
Bolt specific features
Parameter placeholders
Supported parameter placeholder for CQL is ? or string with $ prefix.
Don't use placeholder string with : prefix because CQL use : for labels prefix.
PDO Method reset()
Graph database can be in failure state (error code 02001) and any next message is ignored (error code 02002). Instead of destroying PDO instance and creating new, you can call this method.
PDO::PARAM_LOB
Automatically converts resource or string into instance of Bytes class.
Additional bolt parameter types
| Constant | Description |
|---|---|
| PDO::BOLT_PARAM_FLOAT | |
| PDO::BOLT_PARAM_LIST | Array witch consecutive numeric keys from 0. |
| PDO::BOLT_PARAM_DICTIONARY | Object or array which is not list. |
| PDO::BOLT_PARAM_STRUCTURE | Class extending IStructure. |
| PDO::BOLT_PARAM_BYTES | instance of Bytes class. |
List of usable parameters depends on graph database you use (Neo4j, Memgraph).
Not supported PDO features with Bolt
- Fetch mode
PDO::FETCH_LAZY - Fetch mode
PDO::FETCH_NAMED - PDO method
lastInsertId() - PDOStatement method
rowCount() - Scrollable cursor
Bolt error codes
Standard PDO error codes are related to SQL databases. Graph database have CQL (Cypher query language) and therefore I had to create new list of error codes.
| Error code | Description |
|---|---|
| 01000 | Any authentification error |
| 01001 | Wrong credentials |
| 01002 | Undefined auth type |
| 02000 | Any bolt message error |
| 02001 | Bolt message failure |
| 02002 | Bolt message ignored |
| 03000 | Any transaction error |
| 03001 | Transaction not supported (required bolt>=3 |
| 04000 | Any attribute error |
| 04001 | Attribute not supported |
| 05000 | Any parameter error |
| 05001 | Parameter type not supported |
| 05002 | Parameters placeholder mismatch |
| 06000 | Any fetch error |
| 06001 | Requested fetch column not defined |
| 06002 | Fetch object error |
| 07000 | Any underlying bolt library error |
stefanak-michal/pdo-bolt 适用场景与选型建议
stefanak-michal/pdo-bolt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「Socket」 「neo4j」 「graph database」 「bolt」 「Amazon Neptune」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 stefanak-michal/pdo-bolt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stefanak-michal/pdo-bolt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 stefanak-michal/pdo-bolt 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Symfony integration for Neo4j
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
A PHP Object Graph Mapper for Tinkerpop 3+ compatible Graph Databases (JanusGraph, Neo4j, etc.) that allows you to persist data and run gremlin queries.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-15