Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class StoryRepository {
- private $db;
- function __construct(database $db) {
- $this->db = $db;
- }
- function getStories() {
- $sql = 'SELECT author.name AS authorName, author.surname AS authorSurname, category.name AS catName, article.*
- FROM article
- INNER JOIN author ON article.author_id = author.id
- INNER JOIN category ON article.category_id = category.id';
- /*$sql = 'SELECT student.*, class.name AS class '
- . 'FROM student '
- . 'INNER JOIN class '
- . 'ON student.class_id = class.id';*/
- return $this->db->selectAll($sql);
- }
- function addStory($authorID, $categoryID, $title, $perex, $text, $createdAt) {
- $sql = 'INSERT INTO article
- VALUES(default, :author_id, :category_id, :title, :perex, :text, :created_at)';
- $data = [
- ':author_id' => $authorID,
- ':category_id' => $categoryID,
- ':title' => $title,
- ':perex' => $perex,
- ':text' => $text,
- ':created_at' => $createdAt
- ];
- return $this->db->insert($sql, $data);
- }
- /*function getStory($id) {
- $sql = 'SELECT author.name AS authorName, author.surname AS authorSurname, category.name AS catName, article.*
- FROM article
- INNER JOIN author ON article.author_id = author.id
- INNER JOIN category ON article.category_id = category.id
- WHERE author.id = :id';
- //$sql = 'SELECT * FROM student WHERE id = :id';
- return $this->db->selectOne($sql, [':id' => $id]);
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement