Exemple #1
0
 * Date: 12-01-2016
 * Time: 16:36
 */
require "../../vendor/autoload.php";
$c = new \Slim\Container();
//Create Your container
//Override the default Not Found Handler
$c['notFoundHandler'] = function ($c) {
    return function ($request, $response) use($c) {
        return $c['response']->withStatus(404)->withHeader('Content-Type', 'text/json')->write('{"status":404}');
    };
};
$app = new \Slim\App($c);
$app->group('/discussion', function () {
    include "../../requirements/sqli.php";
    $sqli = new sqli(array("127.0.0.1", "", "", "test"));
    $this->get('', function ($request, $response, $args) use($sqli) {
        echo json_encode($sqli->pull_multiple("select * from diskotioner")->data);
    });
    $this->post('', function ($request, $response, $args) use($sqli) {
        if (isset($_POST['title'])) {
            $insert = $sqli->push("insert into diskotioner (title) VALUES (?)", "s", $_POST['title']);
            if ($insert->affected_rows == 1) {
                return $response->withStatus(201)->write($insert->insert_id);
            }
            return $response->withStatus(400);
        }
        return $response->withStatus(400);
    });
    $this->delete('/{id:[0-9]+}', function ($request, $response, $args) use($sqli) {
        $sqli->push("delete FROM  diskotion_kommentar where fk_kommentar = ?", "i", $args['id']);
Exemple #2
0
<pre>
<?php 
include "sqli.php";
// Connect to the database
$sqli = new sqli(["127.0.0.1", "", "", "test"]);
// Insert three rows to have some data to play with
$insert1 = $sqli->push("insert into test (msg) VALUES (?)", "s", "Just a test");
echo "Insert id:" . $insert1->id . "\n";
$insert2 = $sqli->push("insert into test (msg) VALUES (?)", "s", "Just a test");
echo "Insert id:" . $insert2->id . "\n";
$insert3 = $sqli->push("insert into test (msg) VALUES (?)", "s", "Just a test");
echo "Insert id:" . $insert3->id . "\n\n";
// Show the data form the array
foreach ($sqli->pull_multiple("SELECT id, msg as message FROM test")->data as $row) {
    echo $row['id'] . " : " . $row['message'] . "\n";
}
echo "\n";
// Show one row
echo "First insert row: " . $sqli->pull_once("SELECT msg as message FROM test WHERE id=?", "i", $insert1->id)->data['message'] . "\n";
// Clere the table
echo "Deleted rows:" . $sqli->push("DELETE FROM test")->affected_rows . "\n";
// Some rows left?
echo "Rows left: " . $sqli->pull_multiple("SELECT * FROM test")->count;
/* HERES MY OUTPUT
Insert id:1
Insert id:2
Insert id:3

1 : Just a test
2 : Just a test
3 : Just a test