-
-
Save cidadesites/50798f85917dcd75ccc1 to your computer and use it in GitHub Desktop.
Crud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
?php | |
require_once 'C:\xampp\htdocs\Sitealterdochao\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(); | |
} | |
} | |
?> |
jackmakiyama
commented
Oct 2, 2015
require_once 'C:\xampp\htdocs\Sitealterdochao\classes\DB\DB.php';
Mano, use namespace por favor!
Veja:
Veja um exemplo de camada de persistencia em OOP:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment