Skip to content

Instantly share code, notes, and snippets.

@victorknust
Forked from cidadesites/crud.php
Created December 29, 2015 12:54
Show Gist options
  • Save victorknust/9c1ee268b6773239181b to your computer and use it in GitHub Desktop.
Save victorknust/9c1ee268b6773239181b to your computer and use it in GitHub Desktop.
<?php
require_once 'C:\xampp\htdocs\PainelOO\classes\DB\DB.php';
abstract class Crud extends DB{
protected $table;
abstract public function insert();
abstract public function update($id);
public function find($id){
$sql = "SELECT * FROM $this->table WHERE id = :id";
$stmt = DB::prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetch();
}
public function findAll(){
$sql = "SELECT * FROM $this->table";
$stmt = DB::prepare($sql);
$stmt->execute();
return $stmt->fetchAll();
}
public function delete($id){
$sql = "DELETE FROM $this->table WHERE id = :id";
$stmt = DB::prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
return $stmt->execute();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment