30 lines
705 B
PHP
30 lines
705 B
PHP
<?php
|
|
|
|
namespace Api\Core;
|
|
|
|
class Model {
|
|
protected $db;
|
|
protected $table;
|
|
|
|
public function __construct() {
|
|
$this->db = db();
|
|
}
|
|
|
|
public function all() {
|
|
$stmt = $this->db->query("SELECT * FROM {$this->table}");
|
|
return $stmt->fetchAll();
|
|
}
|
|
|
|
public function find($id) {
|
|
$stmt = $this->db->prepare("SELECT * FROM {$this->table} WHERE id = :id");
|
|
$stmt->execute(['id' => $id]);
|
|
return $stmt->fetch();
|
|
}
|
|
|
|
public function where($column, $value) {
|
|
$stmt = $this->db->prepare("SELECT * FROM {$this->table} WHERE {$column} = :value");
|
|
$stmt->execute(['value' => $value]);
|
|
return $stmt->fetchAll();
|
|
}
|
|
}
|