Browse Source

src: Add a sqlite database

master
Elis Hirwing 1 year ago
parent
commit
d6c3ec7508
Signed by: etu GPG Key ID: D57EFA625C9A925F
2 changed files with 22 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +21
    -0
      public/index.php

+ 1
- 0
.gitignore View File

@@ -1 +1,2 @@
sqlite.db
vendor/

+ 21
- 0
public/index.php View File

@@ -27,6 +27,27 @@ $container['logger'] = function (Slim\Container $c) {
return $logger;
};

$container['db'] = function (Slim\Container $c) {
$pdo = new PDO('sqlite:../sqlite.db');

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

$pdo->exec(
'DROP TABLE IF EXISTS inventory;'
);

$pdo->exec(
'CREATE TABLE inventory (
item_id INTEGER PRIMARY KEY,
item_name TEXT NOT NULL,
item_stock INTEGER NOT NULL
);'
);

return $pdo;
};

/**
* Set up controllers
*/


Loading…
Cancel
Save