Skip to content

lepola/json-database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Json-db by Lepola

Simple json db javascript library, create json 'tables' and save data to it.

Requires JQuery, PHP.

Getting start

PHP for login and logout, Javascript for edit, delete and get table / item.

  1. Copy json-db folder to your website.

  2. Open json-db/config.php and set your database username and password.

  3. For editing, creating or deleting tables / items and selecting protected table data, you need login with php:

     - include 'json-db/config.php';
     - json_db_login($yourusername, $yourpassword);
    
  4. After this you can edit tables with Javascript using json-db/json-db.js.

  5. json-db/index.php is simple adminpanel for db.

PHP functions

  1. include 'config.php';

Log in with config.php username and password.

json_db_login($USERNAME, $PASSWORD);



Logout

json_db_logout();



If you are logged in -> return true, else return false.

json_db_logged_in();

Javascript (json-db.js) functions

Response message format:

{

	response: (object), // if error is 1, this won't exist.

	message: (string),

	error: (0 = No error, 1 = error)

}

Json db library path

json_db.folder.path = "json_db/"; // This is default path. This needs to be valid and <b>use slash at end of path!</b>

Create table, eg:

json_db.createTable("tableName", function(response){

	console.log(response);

});

Create Protected table, you can read only if you are logged in. eg:

json_db.createProtectedTable("tableName", function(response){

	console.log(response);

});

Update table protected status. eg:

json_db.updateTableContent(TABLE_NAME, PROTECTED_STATUS, SUCCESS_FUNCTION);

json_db.updateTable("tableName", 1 /*1 = protected, 0 = non-protected*/, function(response){

	console.log(response);

});

Update table content. This replace old table to JSON_VARIABLE parameter. eg:

json_db.updateTableContent(TABLE_NAME, JSON_VARIABLE, SUCCESS_FUNCTION);

json_db.updateTableContent("tableName", {"name": "test"}, function(response){

	console.log(response);

});

Remove table eg:

json_db.removeTable("tableName", function(response){

	console.log(response);

});

Get table eg:

json_db.getTable("tableName", function(response){

	console.log(response);

});

Get all tables eg:

json_db.getTables(function(response){

	console.log(response);

});

Get item eg:

json_db.getItem(TABLE_NAME, ITEM_INDEX, SUCCESS_FUNCTION);

json_db.getItem("tableName", 0, function(response){

	console.log(response);

});

Edit item eg:

json_db.editItem(TABLE_NAME, ITEM_INDEX, NEW_ITEM, SUCCESS_FUNCTION);

json_db.editItem("tableName", 0, {"item":"newItem"}, function(response){

	console.log(response);

});

Add item eg:

json_db.addItem(TABLE_NAME, ITEM, SUCCESS_FUNCTION);

json_db.addItem("tableName", {"title":"this item will be added."}, function(response){

	console.log(response);

});

License

GNU General Public License v3.0