Пример #1
0
<?php

header('content-type: application/json; charset=utf-8');
header("access-control-allow-origin: *");
require_once __DIR__ . '/class.localdb.php';
$db = new LocalDatabase('db/');
$table = 'todo';
function retrievePostData()
{
    if (count($_POST)) {
        return $_POST;
    } elseif ($post_data = file_get_contents('php://input')) {
        if ($post_json = json_decode($post_data, TRUE)) {
            return $post_json;
        } else {
            parse_str($post_data, $post_variables);
            if (count($post_variables)) {
                return $post_variables;
            }
        }
    }
    return FALSE;
}
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'GET') {
    if (isset($_GET['fakerestapi'])) {
        $array = $db->loadSingleArray($table, $_GET['fakerestapi']);
    } else {
        $array = $db->loadArray($table);
    }
    echo json_encode($array);
Пример #2
0
<?php

$seed = [['id' => uniqid(), 'taskname' => 'Go to Shooping', 'date' => '15/01/2016'], ['id' => uniqid(), 'taskname' => 'Buy daily needs', 'date' => '15/02/2016'], ['id' => uniqid(), 'taskname' => 'Hair cut', 'date' => '15/03/2016']];
require_once __DIR__ . '/class.localdb.php';
$db = new LocalDatabase('db/');
$table = 'todo';
$db->saveArray($table, $seed);
echo 'DB seed succesful!';