Skip to main content

ZTeraDB Configuration Guide

This guide explains how to configure the ZTeraDB PHP client using the ZTeraDBConfig class.


๐ŸŽฏ What is ZTeraDBConfig?

ZTeraDBConfig is a PHP configuration object that contains all authentication details, environment settings, and optional connection settings required to connect your application to ZTeraDB Server.

It is required for every ZTeraDB connection.


๐Ÿงฉ Full Structure

$config = new ZTeraDBConfig([
'client_key' => 'string',
'access_key' => 'string',
'secret_key' => 'string',
'database_id' => 'string',
'env' => 'dev | staging | qa | prod',
'response_data_type' => 'json',
'options' => new Options([
'connection_pool' => new ConnectionPool(
min: 0,
max: 0
)
])
]);

๐Ÿ”Ž Field-by-field Explanation

๐Ÿ”‘ client_keyโ€‹

  • Your unique ZTeraDB account key.
  • Get it from: Dashboard โ†’ Security Credentials.

๐Ÿ” access_keyโ€‹

  • Required for authenticating outgoing requests.
  • You can generate multiple access keys.
  • Only one active access key is allowed at a time.

๐Ÿงฉ secret_keyโ€‹

  • Secret signature key used to verify request authenticity.
  • You will only see it once when creating it.
  • Never share it or commit it to Git.

๐Ÿ—„ database_idโ€‹

  • Unique ID of your ZTeraDB database.
  • Example:
    "7K3WHGOJKJJEJ3PFJM407QO25F"

๐ŸŒ envโ€‹

Defines which ZTeraDB environment your database belongs to.

Allowed values:

  • dev -> Development Environment
  • staging -> Staging Environment
  • qa -> QA Environment
  • prod -> Production Environment

Usage example:

'env' => ENVS::dev

๐Ÿ“ฆ response_data_typeโ€‹

  • Currently supports only "json":
'response_data_type' => ResponseDataTypes::json
  • Future formats may be added later.

โš™๏ธ options.connection_poolโ€‹

You can control automatic connection pooling:

FieldMeaning
minMinimum persistent connections ZTeraDB keeps open
maxMaximum number of allowed connections

Example:

'options' => new Options([
'connection_pool' => new ConnectionPool(
min: 2,
max: 10
)
])

If not set โ†’ ZTeraDB manages this automatically.


๐Ÿงช Complete Example

use ZTeraDB\Config\ZTeraDBConfig;
use ZTeraDB\Config\Options;
use ZTeraDB\Config\ConnectionPool;
use ZTeraDB\Config\ResponseDataTypes;
use ZTeraDB\Config\ENVS;

$config = new ZTeraDBConfig([
'client_key' => '<Your ZTeraDB client key>',
'access_key' => '<Your ZTeraDB access key>',
'secret_key' => '<Your ZTeraDB secret key>',
'database_id' => '<Your ZTeraDB database id>',
'env' => ENVS::dev,
'response_data_type' => ResponseDataTypes::json,
'options' => new Options([
'connection_pool' => new ConnectionPool(min: 1, max: 5)
])
]);

โš ๏ธ Common Mistakes (Read This!)

โŒ Wrong environment name
โœ” Use only: "dev", "staging", "qa", "prod"

โŒ Missing secret key
โœ” Ensure .env contains all required fields

โŒ Hard-coding credentials in code
โœ” Store all keys in .env files only

โŒ Not enabling connection pooling in high-traffic apps
โœ” Use appropriate min & max settings


๐ŸŽ‰ You are ready to create a connection!

Continue to:
๐Ÿ‘‰ zteradb-connection