Skip to content

RanaAhmar/php-json-db-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP JSON DB Manager 🗄️

PHP Version License Size Dependencies

A lightweight, zero-dependency PHP class to use JSON files as a robust NoSQL database.

Need a simple database but don't want the overhead of setting up MySQL/PostgreSQL? php-json-db-manager turns any simple JSON file into a fully queryable NoSQL database with strict error handling, built-in lock mechanisms for concurrency, and a fluent query interface.

🌟 Key Features

  • Zero Configuration: Just point it to a .json file and start querying.
  • Fluent API: Chainable methods for intuitive data manipulation (where(), insert(), update(), etc.).
  • Concurrency Safe: Utilizes flock() under the hood to ensure safe read/writes during simultaneous requests.
  • Incredibly Fast: Entirely loaded into memory for lightning-fast reads on small to medium datasets.

📚 Table of Contents

📦 Installation

Include via Composer (if published) or drop the class directly into your project.

composer require ranaahmar/php-json-db-manager

(Or simply copy src/JsonDB.php into your /lib folder).

🚀 Quick Start

require 'vendor/autoload.php';
// Or include directly: require 'src/JsonDB.php';

use Ahmar\Database\JsonDB;

// Initialize it (will create 'users.json' if it does not exist)
$db = new JsonDB('users.json');

// 1. Insert Data
$db->insert([
    'id' => 1,
    'name' => 'Ahmar Hussain',
    'role' => 'admin'
]);

// 2. Fetch Data
$users = $db->all();
echo json_encode($users);

🔍 Query API

find(string $key, $value)

Retrieve items where a specific key matches a value.

$admins = $db->find('role', 'admin');

update(string $key, $value, array $newData)

Finds records matching $key = $value and merges $newData into those records.

$db->update('id', 1, [
    'role' => 'superadmin'
]);

delete(string $key, $value)

Deletes records that match the criteria.

$db->delete('id', 1);

truncate()

Wipes the entire database back to an empty array.

$db->truncate();

🤝 Contributing

Contributions, issues, and feature requests are welcome!

📄 License

This project is MIT licensed. See LICENSE.


🚀 Discover More from Stackaura

If you found this tool useful, check out our other high-performance web utilities and follow Ahmar Hussain for more open-source excellence.

🌟 Featured Projects

🔗 Stay Connected


About

A lightweight, zero-dependency PHP class to use JSON files as a robust NoSQL database.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages