N
N
Natalya Chobot2017-07-06 17:03:15
Database
Natalya Chobot, 2017-07-06 17:03:15

How to create a DB using json (json-server)?

I don’t know how to write $path when creating a database variable
$jdb = new Jsondb($path);
$path - the path from the root to the folder where the files will be stored. Default $path = $_SERVER["DOCUMENT_ROOT"].'/jdb/'.

I also do not understand what kind of keys:
Create. Creating a table.
$jdb->create($table, $keys);
$keys - array of table keys and their characteristics. Auto_increment and default are supported.
Example:

$keys = Array(
  'id'=>Array('auto_increment'),
  'title'=>Array('default'=>'habrahabr'), 
  'posts', 
            'userId'
);
$jdb->create('habr', $keys);

or keys it also are fields of the table?
Source article from habr: https://habrahabr.ru/post/119719/
Maybe someone has an example of creating tables.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Natalya Chobot, 2017-07-06
@nata-ponchik

the answer was found:
it was just necessary to write in the db.json file like this:

"posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}

posts - this is the name of the table, and inside the curly braces of the table field, which immediately sets the values
, it turns out that I went too hard

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question