GithubHelp home page GithubHelp logo

tech96 / jsondb.class.php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from strzlee/jsondb.class.php

0.0 1.0 0.0 11 KB

JSON Databaseclass. Handle JSON-Files like a very, very simple DB.

License: Do What The F*ck You Want To Public License

PHP 100.00%

jsondb.class.php's Introduction

This is a fork of Straussn's JSON-Databaseclass.

  • Added createTable() method for creating new tables (.json files)
  • Added optional table creation on insert() method, if table doesn't exist.

Use it like this:

$db = new JsonDB("./my_json_database/");

$db->createTable("my_new_table");

$db->insert("my_new__new_table", array("newkey2" => "newvalue2"), true);

$my_another_new_table = new JsonTable("./string_statuses/demo14.json", true);
$my_another_new_table->insert(array("newkey2" => "newvalue2"));

Straussn's JSON-Databaseclass

Handle JSON-Files like a very, very simple DB. Useful for little ajax applications.

Example:

test.json

[  
{"ID": 0, "Name": "Josef Brunzer", "Age": 43},  
{"ID": 1, "Name": "Harald Beidlpraka", "Age": 34},  
{"ID": 2, "Name": "Heinz Goschnfuada", "Age": 67},  
{"ID": 3, "Name": "Gerald Ofnsacka", "Age": 43}  
]

test.php

require "JsonDB.class.php";

$db = new JsonDB("./data/"); //parameter => directory to your json files

$result = $db->select("test","Age",43); //parameter => json file (tablename), key, value

result:

array(2) {
[0]=> array(3) { ["ID"]=> int(0) ["Name"]=> string(13) "Josef Brunzer" ["Age"]=> int(43) }
[1]=> array(3) { ["ID"]=> int(3) ["Name"]=> string(15) "Gerald Ofnsacka" ["Age"]=> int(43) }
}

If you use a different file extension as ".json", set them via "JsonDB -> setExtension ('.example')"


Method Overview:

JsonDB -> select ( "table", "key", "value" ) - Selects multible lines which contains the key/value and returns it as array

JsonDB -> selectAll ( "table" ) - Returns the entire file as array

JsonDB -> update ( "table", "key", "value", ARRAY ) - Replaces the line which corresponds to the key/value with the array-data

JsonDB -> updateAll ( "table", ARRAY ) - Replaces the entire file with the array-data

JsonDB -> insert ( "table", ARRAY ) - Appends a row, returns true on success

JsonDB -> delete ( "table", "key", "value" ) - Deletes all lines which corresponds to the key/value, returns number of deleted lines

JsonDB -> deleteAll ( "table" ) - Deletes the whole data, returns "true" on success


If you use only one json file to store data, you can also use the "JsonTable" Class:

$db = new JsonTable("./data/test.json"); //parameter => your json file

$result = $db -> selectAll();

$db -> update ( "ID", 1, array("ID" => 1, "Name" => "Fani Zwidawurzn", "Age" => 66));

$db -> delete( "ID", 2 );

In this case, you don't have always to specify the "tablename".

jsondb.class.php's People

Contributors

oytuntez avatar saitima avatar strzlee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.