mitchellurgero/jsondatabase

Flat-file Database that uses JSON to store data in a file structure similar to MySQL.

dev-master 2018-04-25 15:53 UTC

This package is not auto-updated.

Last update: 2024-04-28 03:30:45 UTC


README

This DB class supports the following functions:

  • init("DATABASE_NAME", "DATABASE_LOCATION" = null); //Load or create new database, then select it. (Optionally give a location to store the databse)
  • insert("TABLE_NAME", '{"data":"in","JSON":"format"}', int = null);//Insert or add a new row into given table (Optional 3rd option: replace given row number)
  • select("TABLE_NAME", "WHERE" = null, "EQUALS" = null);//get data from selected row
  • create_table("TABLE_NAME");//Create a new table with the given name.
  • delete_table("TABLE_NAME");//Delete the given table.
  • dump_tables();//Dump all tables AND their data (Mostly for backup purposes.)
  • check_table("TABLE_NAME");//Check if a table exists. Returns number of rows if table exists.
  • list_tables();//List all available tables in selected database.
  • import("JSON_STRING_OF_DB_BACKUP");//import a database backup and restore into the given database.

Things to note:

  • row_id is the row number. This is not written to the db BUT generated on the fly. and always exists as a part of the row data
  • dump_tables() will always take a little bit of time because it dumps ALL THE TABLES TO AN ARRAY.

How To Use

include('db.php');

$db = new JSONDatabase("DATABASE_NAME");

$db->functionName(options);

Install

Either git clone this repository, or use composer require mitchellurgero/jsondatabase to install via composer.