🚀 Quickstart (10-Minute Beginner Setup)
Welcome to ZTeraDB! This guide is engineered for developers who want to integrate the ZTeraDB PHP Client into their applications rapidly. Follow along step-by-step to execute your first database query in under 10 minutes.
📌 Table of Contents
- 📋 System Requirements
- 📦 1. Installation
- 🔐 2. Environment Configuration
- 🔌 3. Establish a Connection Instance
- 📑 4. Run Your First SELECT Query
- ⚡ 5. Basic CRUD Mutations & Filters
- 🎉 6. Next Steps
📋 System Requirements
Before installing, ensure your local environment satisfies the runtime prerequisites:
| Requirement | Specification |
|---|---|
| PHP Version | PHP 7.2 or higher (Download from php.net) |
| Extensions | sockets extension must be enabled in your php.ini file |
| Package Registry | Available via Packagist |
📦 1. Installation
Integrate the official ZTeraDB package using Composer. You can install it from the main repository registry or target a specific release configuration directly from version control.
Option 1: Via Composer (Recommended)
Run the following command in your terminal to install the ZTeraDB client:
# Using composer
composer require zteradb/zteradb-php
Option 2: From GitHub Repository
Alternatively, you can pull the package directly from GitHub. Add the repository to your composer.json file:
{
"repositories": [
{
"type": "vcs",
"url": "[https://github.com/zteradb/zteradb-php](https://github.com/zteradb/zteradb-php)"
}
],
"require": {
"zteradb/zteradb-php": "v2.0.0"
}
}
Then execute a strict install command targeting the static constraint tag:
composer require zteradb/zteradb-php:v2.0.0
🔐 2. Environment Configuration
Create an isolated environment configuration file named .env inside your structural root folder path to safely externalize pipeline security variables.
# .env
CLIENT_KEY="your_client_identity_string"
ACCESS_KEY="your_active_access_token"
SECRET_KEY="your_cryptographic_signature_key"
DATABASE_ID="your_cluster_instance_id"
ZTERADB_HOST=<Your ZTeraDB Server HOST>
ZTERADB_PORT=<Your ZTeraDB Server PORT>
ZTERADB_ENV=DEV
⚠️ Production Security Watch: Never commit your localized .env variables into public source control networks. Add .env explicitly into your project's .gitignore rules.
🔌 3. Establish a Connection Instance
Create a reusable connection gateway file named db.php to initialize and return your storage cluster instance wrapper.
<?php
// db.php
require_once __DIR__ . '/vendor/autoload.php';
use ZTeraDB\Config\ZTeraDBConfig;
use ZTeraDB\Connection\ZTeraDBConnection;
use ZTeraDB\Config\ResponseDataTypes;
use ZTeraDB\Config\ENVS;
/**
* Initializes and returns a singleton-style ZTeraDB Connection instance.
*
* @return ZTeraDBConnection
*/
function getDB(): ZTeraDBConnection {
$config = new ZTeraDBConfig([
'client_key' => getenv('CLIENT_KEY'),
'access_key' => getenv('ACCESS_KEY'),
'secret_key' => getenv('SECRET_KEY'),
'database_id' => getenv('DATABASE_ID'),
'env' => ENVS::dev,
'response_data_type' => ResponseDataTypes::json
]);
return new ZTeraDBConnection(
getenv('ZTERADB_HOST'),
(int) getenv('ZTERADB_PORT'),
$config
);
}
📑 4. Run Your First SELECT Query
Create an execution file named test.php to fetch table data out of your live database node matrix.
<?php
// test.php
require_once __DIR__ . '/db.php';
use ZTeraDB\Query\ZTeraDBQuery;
// 1. Establish data storage connection engine driver
$db = getDB();
// 2. Build the query extraction tree
$query = (new ZTeraDBQuery('user'))->select();
// 3. Process execution against cluster nodes
$result = $db->run($query);
// 4. Clean-print response row arrays
foreach ($result as $row) {
print_r($row);
}
// 5. Explicitly terminate network handle resources
$db->close();
Execute the test runtime sequence inside your CLI environment:
php test.php
🎉 If execution logic routing configuration matches your credentials, active user matrices rows will output directly to your terminal screen.
⚡ 5. Basic CRUD Mutations & Filters
Below is an onboarding list containing structured code snippets for typical mutations, conditional writes, and filter configurations.
Insert a Record
$query = (new ZTeraDBQuery('user'))
->insert()
->fields([
'email' => 'test@example.com',
'password' => 'secure_hashed_password',
'status' => true
]);
$result = $db->run($query);
echo 'Generated Auto-Increment ID: ' . $result['last_insert_id'];
Update a Record
$query = (new ZTeraDBQuery('user'))
->update()
->fields(['status' => false])
->filter(['id' => 1]);
$result = $db->run($query);
Delete a Record
$query = (new ZTeraDBQuery('user'))
->delete()
->filter(['id' => 5]);
$result = $db->run($query);
Simple Scalar Filtering
For straightforward exact-matches on properties, pass static key-value configurations inside the .filter() assignment helper.
$query = (new ZTeraDBQuery('user'))
->select()
->filter(['status' => true]);
Advanced Functional Filtering
For processing compound mathematical operations or parsing programmatic dynamic validations at database runtime level, load logic trees into .filterCondition().
// Compiles operational math evaluating: (price * quantity) > 500
$query = (new ZTeraDBQuery('product'))
->select()
->filterCondition(
ZTGT([
ZTMUL(['price', 'quantity']),
500
])
);
🎉 6. Next Steps
You are officially setup! You have successfully managed your dependency assembly installation layer, connected to database endpoints, managed query statements, and mapped out simple filters.
👉 Up Next: If you encounter environment blockades or configuration exceptions, consult the comprehensive Troubleshooting Guide blueprint.