Browse Source

move createBlogs SQL to DB class

Namespaces
Ruben De Baets 2 years ago
parent
commit
dba62b4c80
2 changed files with 12 additions and 7 deletions
  1. 1
    7
      public/index.php
  2. 11
    0
      src/DB.php

+ 1
- 7
public/index.php View File

@@ -94,14 +94,8 @@ $app->map(['GET', 'POST'], '/blog/create', function (Request $request, Response
} else {
$data = $request->getParsedBody();
global $db;
$db->enableExceptions(false);
//$sql = "INSERT INTO blogs (slug, title, content) VALUES ('" . $data['slug'] . "', '" . $data['title'] . "', '" . $data['content'] . "')";
$stmt = $db->prepare("INSERT INTO blogs (slug, title, content) VALUES (:slug, :title, :content)");
$stmt->bindValue(':slug', $data['slug'], SQLITE3_TEXT);
$stmt->bindValue(':title', $data['title'], SQLITE3_TEXT);
$stmt->bindValue(':content', $data['content'], SQLITE3_TEXT);
$res = $stmt->execute();

$res = $db->createBlog($data);
if ($res) {
return $response->withHeader('Location', '/')->withStatus(302);
} else {

+ 11
- 0
src/DB.php View File

@@ -23,4 +23,15 @@ class DB extends SQLite3
return false;
}
}

public function createBlog($data)
{
$this->enableExceptions(false);
$stmt = $this->prepare("INSERT INTO blogs (slug, title, content) VALUES (:slug, :title, :content)");
$stmt->bindValue(':slug', $data['slug'], SQLITE3_TEXT);
$stmt->bindValue(':title', $data['title'], SQLITE3_TEXT);
$stmt->bindValue(':content', $data['content'], SQLITE3_TEXT);
$res = $stmt->execute();
return $res;
}
}

Loading…
Cancel
Save