v1.1 2023-03-13 14:25 UTC

This package is auto-updated.

Last update: 2024-10-13 18:01:30 UTC


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.

Bolt specification

Buy Me a Coffee at ko-fi.com

Requirements

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

Packagist

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

PDO constructor available options

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

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.