PHP Classes

How to Create and Query a PHP JSON Database Using the Package jsqldb: Examples to use JSQLDB to store data in JSON files

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-05-10 (Yesterday) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
jsqldb 0.0.1Custom (specified...8.4Databases, Files and Folders, PHP 8
Description 

Author

This package provides examples to use JSQLDB to store data in JSON files.

It has example scripts that can use Ascoos framework JSQLDB package to show how to create and query a database using files that contain data in the JSON format.

Currently it provides examples to:

- Create a database

- Create a database user

- Insert new table records

- Query table records

Picture of Christos Drogidis
  Performance   Level  
Name: Christos Drogidis <contact>
Classes: 38 packages by
Country: Greece Greece
Innovation award
Innovation award
Nominee: 22x

Winner: 4x

Instructions

Please read this document to learn how to configure, create and query a database stored in JSON files.

Details

JSQL Database

JSQLDB - JSON Database Engine with SQL Syntax for Ascoos OS

JSQLDB is the built?in database engine of Ascoos OS. It is based entirely on JSON files, while supporting SQL?like queries for everyday data operations. It is designed for applications that require portability, security, speed, and complete independence from MySQL, MariaDB or SQLite.

The engine is fully integrated into the Ascoos OS kernel, and all interaction with the database is done through the TJSQLDBHandler. All paths, files and configuration values are managed by the operating system itself, ensuring stability and security.

At a glance

$db = new TJSQLDBHandler($conf);

$db->setSQLQuery("
    SELECT title, created_at
    FROM #__articles
    ORDER BY created_at DESC
    LIMIT 5
");

$db->execute();

print_r($db->getResults());

$db->close();

What JSQLDB provides

JSQLDB stores all data in JSON files, supports indexing, compression for TEXT fields, and SQL syntax for CRUD operations. The engine is optimized for PHP 8.4+ and uses the TUTF8 Grapheme Engine of Ascoos OS, ensuring that text is processed based on visible characters rather than raw bytes.

This means the database never breaks characters in the middle, calculates the correct length of complex symbols (emoji, flags, combined characters), and produces indexes that behave correctly across all languages.

Configuration and Initialization

JSQLDB requires no installation. The main paths (config, users, root path) are defined in the Ascoos OS configuration and are encrypted.

Example system configuration:

'db' => [
    'db_driver' => 'jsqldb',
    'jsqldb' => [
        'config_path'  => '/path/to/jsqldb/conf/config.json',
        'users_path'   => '/path/to/jsqldb/conf/users.json',
        'db_root_path' => '/path/to/jsqldb/db',
        'dbname'       => 'jsqldb',
    ],
],

Each domain/subdomain may have its own database with its own credentials:

'db' => [
    'db_driver' => 'jsqldb',
    'jsqldb' => [
        'host' => 'localhost',
        'port' => 28031,
        'user' => 'user',
        'pass' => 'pass',
        'dbname' => 'test_db',
    ],
],

Example 1 - Creating a database, a table and inserting multiple records

The following example (examples/example3.php) demonstrates a complete workflow: creating a database, assigning a user, creating a table, performing a batch insert and retrieving data.

$jsqldb = new TJSQLDBHandler($conf, [
    'tables_prefix' => 'ascoos_',
    'default_compression' => true
]);

$jsqldb->createDatabase('test_db');
$jsqldb->createUser('user', 'pass', 'test_db');
$jsqldb->selectDatabase('test_db');

$sql = "CREATE TABLE IF NOT EXISTS `#__articles` (...);";
$jsqldb->setSQLQuery($sql);
$jsqldb->execute();

$insertQuery = "INSERT INTO #__articles (...) VALUES (?, ?, ?, ?, ?, ?)";
$jsqldb->bind('iiiiss', [$data], $insertQuery);
$jsqldb->execute();

$jsqldb->setSQLQuery("SELECT * FROM #__articles LIMIT 10");
$jsqldb->execute();
$data = $jsqldb->getResults();

$jsqldb->close();

Example 2 - News system with JOIN and published articles

The second example (examples/example4.php) shows a more complete scenario: a news table with slug, excerpt, content, timestamps, ENUM status and JOIN with users and categories.

$jsqldb->createDatabase('myapp_2026');
$jsqldb->createUser('webuser', 'strongPass123!', 'myapp_2026');
$jsqldb->selectDatabase('myapp_2026');

$createTable = "CREATE TABLE IF NOT EXISTS `#__news` (...);";
$jsqldb->setSQLQuery($createTable);
$jsqldb->execute();

$insertQuery = "INSERT INTO #__news (...) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$jsqldb->bind('ssssiiis', $data, $insertQuery);
$jsqldb->execute();

$selectQuery = "
    SELECT n.id, n.title, n.excerpt, n.published_at,
           u.username AS author_name,
           c.name     AS category_name
    FROM #__news n
    LEFT JOIN #__users u ON u.id = n.author_id
    LEFT JOIN #__categories c ON c.id = n.category_id
    WHERE n.status = 'published'
      AND n.published_at <= NOW()
    ORDER BY n.published_at DESC
    LIMIT 10
";

$jsqldb->setSQLQuery($selectQuery);
$jsqldb->execute();
$articles = $jsqldb->getResults();

The TUTF8 Grapheme Engine

JSQLDB uses the TUTF8 Engine of Ascoos OS, which measures and processes text based on Grapheme Clusters.

Example:

| Character | strlen() | mb_strlen() | utf8->strlen() | |-----------|----------|-------------|----------------| | ? | 4 | 1 | 1 | | ?? | 8 | 2 | 1 | | ?? | 8 | 2 | 1 |

This ensures:

  • correct storage
  • correct indexing
  • no broken characters
  • full multilingual compatibility

License

JSQLDB is part of Ascoos OS and is distributed under the official project license.


  Files folder image Files (5)  
File Role Description
Plain text file example.php Example Initial
Plain text file LICENSE-EL.md Lic. Initial
Plain text file LICENSE.md Lic. Initial
Plain text file README-EL.md Doc. Initial
Plain text file README.md Doc. Readme

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadjsqldb-2026-05-10.zip
Downloadjsqldb-2026-05-10.tar.gz
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Ascoos OS Download .zip .tar.gz The version 26 is based on Ascoos OS Required
 Version Control Unique User Downloads  
 100%
Total:0
This week:0