JSON backed flat file db for PHP
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
db.php
db_template.json
index.php

README.md

JSONDatabase class written by Mitchell Urgero info@urgero.org

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.
  • 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);