瀏覽代碼

move class myDB to src + make namespace

customers
Ramdan Katakpawou 2 年之前
父節點
當前提交
2082c52ea4
共有 4 個文件被更改,包括 28 次插入13 次删除
  1. 二進制
      private/webshop.db
  2. 15
    13
      public/index.php
  3. 0
    0
      src/DB/.gitkeep
  4. 13
    0
      src/DB/DB.php

二進制
private/webshop.db 查看文件


+ 15
- 13
public/index.php 查看文件

@@ -1,24 +1,26 @@
<?php
session_start();
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
Use Shop\DB\DB;

require __DIR__ . '/../vendor/autoload.php';
class myDB extends \SQLite3
// maak namespace in een aangemaakte file en verplaats mydb
/*class myDB extends \SQLite3
{
public function __construct()
{
$this->open('../private/webshop.db');
}
}

}*/

$app = AppFactory::create();

$app->map(['GET', 'POST'], "/orders/{client}/create", function (Request $request, Response $response, array $args) {
if ($request->getMethod() == "GET") {
$db2 = new myDB();
$db2 = new DB();
$stmt2 = $db2->prepare("SELECT * FROM clients WHERE id = " . $args['client']);
$res2 = $stmt2->execute();
$a = $res2->fetchArray(SQLITE3_ASSOC);
@@ -33,7 +35,7 @@ $app->map(['GET', 'POST'], "/orders/{client}/create", function (Request $request
return $response;
} else {
$ref = $request->getParsedBody()['reference'];
$db2 = new myDB();
$db2 = new DB();
$sql = "insert into orders (reference, customer_id, vat, subtotal, total) values ('" . $ref . "', " . $args['client'] . ",0,0,0)";
$db2->exec($sql);
return $response->withHeader('Location', '/orders/' . $args['client']);
@@ -42,7 +44,7 @@ $app->map(['GET', 'POST'], "/orders/{client}/create", function (Request $request

// Route with optional params, see https://www.slimframework.com/docs/v4/objects/routing.html#how-to-create-routes section Optional segments
$app->get('/orders[/{client}]', function (Request $request, Response $response, array $args) {
$db = new myDB();
$db = new DB();

if ($args['client']) {
// orders 1 client
@@ -51,7 +53,7 @@ $app->get('/orders[/{client}]', function (Request $request, Response $response,
$res = $stmt->execute();

// naam van de klant
$db2 = new myDB();
$db2 = new DB();
$stmt2 = $db2->prepare("SELECT * FROM clients WHERE id = " . $args['client']);
$res2 = $stmt2->execute();
$a = $res2->fetchArray(SQLITE3_ASSOC);
@@ -86,7 +88,7 @@ $app->get('/orders[/{client}]', function (Request $request, Response $response,
$app->map(['GET', 'POST'], "/order/{id}/create", function (Request $request, Response $response, array $args) {

if ($request->getMethod() == "GET") {
$db2 = new myDB();
$db2 = new DB();
$stmt2 = $db2->prepare("SELECT * FROM orders WHERE id = " . $args['id']);
$res2 = $stmt2->execute();
$a = $res2->fetchArray(SQLITE3_ASSOC);
@@ -105,7 +107,7 @@ $app->map(['GET', 'POST'], "/order/{id}/create", function (Request $request, Res
} else {
$productid = $request->getParsedBody()['id'];
$qty = $request->getParsedBody()['qty'];
$db2 = new myDB();
$db2 = new DB();

// vraag details van het product op
$sqlproduct = "select * from products where id = " . $productid;
@@ -135,7 +137,7 @@ $app->map(['GET', 'POST'], "/order/{id}/create", function (Request $request, Res

$app->get('/order/{id}', function (Request $request, Response $response, array $args) {

$db = new myDB();
$db = new DB();

// detail orderlijnen
$sql = "SELECT * FROM order_lines o LEFT JOIN products p on o.product_id = p.id where o.order_id = " . $args['id'];
@@ -143,7 +145,7 @@ $app->get('/order/{id}', function (Request $request, Response $response, array $
$res = $stmt->execute();

// detail order
$db2 = new myDB();
$db2 = new DB();
$stmt = $db2->prepare("SELECT * FROM orders WHERE id = " . $args['id']);
$res2 = $stmt->execute();
$a = $res2->fetchArray(SQLITE3_ASSOC);
@@ -167,7 +169,7 @@ $app->get('/order/{id}', function (Request $request, Response $response, array $


$app->get('/customers', function (Request $request, Response $response, array $args) {
$db = new myDB();
$db = new DB();
$sql = "SELECT * FROM clients";
$stmt = $db->prepare($sql);
$res = $stmt->execute();

+ 0
- 0
src/DB/.gitkeep 查看文件


+ 13
- 0
src/DB/DB.php 查看文件

@@ -0,0 +1,13 @@
<?php

namespace Shop\DB;

use SQLite3;

class DB extends SQLite3
{
public function __construct()
{
$this->open('../private/webshop.db');
}
}

Loading…
取消
儲存