Book.php 619 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 31.07.18
  6. * Time: 10:58
  7. */
  8. class Book extends Model
  9. {
  10. public function __construct()
  11. {
  12. static::$table = "book";
  13. static::$fields = ['name', 'year', 'user_id'];
  14. static::$pk = "id";
  15. parent::__construct();
  16. }
  17. public function createRow(string $name, string $year, string $user_id)
  18. {
  19. $query =
  20. "INSERT INTO" . self::$table . " (`" . implode("`, `", self::$fields) . "`)" .
  21. " VALUES (" . $name . ", " . $year . ", " . $user_id . ");";
  22. $this->connection->exec($query);
  23. }
  24. }