PHP code example of prismdb / client

1. Go to this page and download the library: Download prismdb/client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

prismdb / client example snippets


use PrismDb\Client;
use PrismDb\Q;
use PrismDb\U;

$db = Client::connect(host: '127.0.0.1', port: 4444, username: 'admin', password: 'admin');

// SQL
$db->sql('CREATE TABLE users (id BIGINT PRIMARY KEY, name TEXT, age BIGINT)');
$db->sql("INSERT INTO users VALUES (1,'alice',30),(2,'bob',25)");
$res = $db->sql('SELECT name, age FROM users WHERE age >= 30 ORDER BY age');
foreach ($res->rows as $row) echo "{$row['name']} {$row['age']}\n";

// Key/value
$db->kv->put('sessions', 'sid-1', 'payload');
$v = $db->kv->get('sessions', 'sid-1');           // string|null

// Documents, with query operators
$db->doc->insertOne('people', ['name' => 'carol', 'age' => 41, 'city' => 'NYC']);
$adults = $db->doc->find('people', Q::and(Q::eq('city', 'NYC'), Q::gt('age', 30)));

// A transaction is atomic across all three models
$db->begin();
$db->sql("INSERT INTO users VALUES (3,'dave',50)");
$db->kv->put('sessions', 'sid-2', 'tx');
$db->commit();                                     // or $db->abort()

$db->close();

Q::all();
Q::eq('f', $v); Q::ne; Q::gt; Q::lt; Q::gte; Q::lte;
Q::in('f', [$a, $b]); Q::nin('f', [$a, $b]);
Q::exists('f', true);
Q::and($a, $b); Q::or($a, $b); Q::not($a);

$db->doc->updateOne('people', Q::eq('name', 'carol'), [
    U::set('city', 'Boston'),
    U::inc('age', 1),
    U::unset('temp'),
]);