PHP SDK
A single-file PHP client for servers (Laravel, WordPress plugins, plain PHP). Download ClickBase.php. Requires PHP 7.4+ with curl & json.
<?php
require "ClickBase.php";
$cb = new ClickBase("my-shop", "cb_sk_SECRET", "https://clickbase.thepakclicktes.com");
// Database
$order = $cb->db("orders")->add(["item" => "Chai", "qty" => 2], null, $ownerUid);
$rows = $cb->db("orders")->where("status", "==", "paid")->orderBy("createdAt", "desc")->limit(20)->docs();
$cb->db("orders")->update($order["id"], ["status" => "done"], ["qty" => 1]); // merge + increment
$cb->db("orders")->batch([["type" => "delete", "id" => "abc"]]);
// Users
$user = $cb->auth->createUser(["email" => "a@b.com", "password" => "secret1", "displayName" => "Ali"]);
$cb->auth->setClaims($user["uid"], ["admin" => true]);
$tokens = $cb->auth->createToken("a@b.com"); // custom sign-in from your own login form
$claims = ClickBaseAuth::verifyTokenLocal($jwt, $PROJECT_JWT_SECRET, "my-shop"); // no network call
// Push + Email + Files
$cb->push->toTopic("news", "New post", "Read it now", "/blog/1");
$cb->email->send(["to" => "a@b.com", "subject" => "Hello {{name}}", "html" => "<p>Hi {{name}}</p>", "vars" => ["name" => "Ali"]]);
$file = $cb->storage->upload("/tmp/receipt.pdf");
// Act as an end user (their access token) so security rules apply
$cb->asUser($accessTokenFromClient)->db("orders")->docs();
// Errors
try { $cb->db("orders")->doc("missing"); } catch (ClickBaseException $e) { echo $e->getCodeString(), ": ", $e->getMessage(); }Realtime from PHP
Servers usually poll: $cb->db("orders")->changes($sinceCursor) returns {events, cursor}. Call it every few seconds from a cron/worker.
Was this page helpful? Tell us. · Download SDK