🚀 ZTeraDB Quickstart Guide (10-Minute Beginner Setup)
Welcome!
This guide is designed for complete beginners and developers who want to start using ZTeraDB in PHP as fast as possible.
Follow this guide step-by-step, and you will run your first ZTeraDB query in under 10 minutes.
✅ 1. Install ZTeraDB PHP Client
Install using Composer:
composer require zteradb/zteradb-php
Or install directly from GitHub (latest dev build):
{
"repositories": [
{ "type": "vcs", "url": "https://github.com/zteradb/zteradb-php" }
],
"require": {
"zteradb/zteradb-php": "<latest version>"
}
}
Then run:
composer install
✅ 2. Add Your .env Configuration
Inside your project, create:
.env
Add the following (replace values):
CLIENT_KEY=YOUR_CLIENT_KEY
ACCESS_KEY=YOUR_ACCESS_KEY
SECRET_KEY=YOUR_SECRET_KEY
DATABASE_ID=YOUR_DATABASE_ID
ZTERADB_HOST=db1.zteradb.com
ZTERADB_PORT=7777
ZTERADB_ENV=dev
⚠️ Never commit .env to GitHub!
✅ 3. Create a Connection File
Create:
db.php
Add this:
<?php
require_once "vendor/autoload.php";
use ZTeraDB\Config\ZTeraDBConfig;
use ZTeraDB\Connection\ZTeraDBConnection;
use ZTeraDB\Config\ResponseDataTypes;
use ZTeraDB\Config\ENVS;
function getDB() {
$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:
test.php
Add this:
<?php
require_once "db.php";
use ZTeraDB\Query\ZTeraDBQuery;
$db = getDB();
$query = (new ZTeraDBQuery("user"))->select();
$result = $db->run($query);
foreach ($result as $row) {
print_r($row);
}
$db->close();
Run it:
php test.php
🎉 If everything is correct, your user rows will print!
⚡ 5. INSERT Example
$query = (new ZTeraDBQuery("user"))
->insert()
->fields([
'email' => 'test@example.com',
'password' => 'pwd',
'status' => true
]);
$result = $db->run($query);
echo $result['last_insert_id'];
⚙ 6. UPDATE Example
$query = (new ZTeraDBQuery("user"))
->update()
->fields(['status' => false])
->filter(['id' => 1]);
❌ 7. DELETE Example
$query = (new ZTeraDBQuery("user"))
->delete()
->filter(['id' => 5]);
🔍 8. Filtering (Simple)
$query->filter(['status' => true]);
🔥 9. Filtering (Advanced)
$query->filterCondition(
ZTGT([
ZTMUL(['price', 'quantity']),
500
])
);
🎉 10. You Are Ready!
You now know:
- How to install ZTeraDB
- How to configure it
- How to connect
- How to run all basic queries
👉 Next recommended file:
troubleshooting.md