con = $con; } public function insertImage(Image $img) { $query = "INSERT INTO Image (`nom`, `taille`, `type`, `desc`, `blob`) VALUES ( :n, :t, :ty, :d, :b)"; $this->con->executeQuery($query, array( ':n' => array($img->getName(), PDO::PARAM_STR), ':t' => array($img->getTaille(), PDO::PARAM_STR), ':ty' => array($img->getType(), PDO::PARAM_STR), ':d' => array("desc", PDO::PARAM_STR), ':b' => array($img->getBlob(), PDO::PARAM_STR) )); } public function insert(int $id,string $name, string $desc, string $taille, string $type, string $blob) { $query = 'INSERT INTO Image VALUES (:i, :n, :t, :ty, :d, :b)'; $this->con->executeQuery($query, array( ':i' => array($id,PDO::PARAM_INT), ':n' => array($name, PDO::PARAM_STR), ':t' => array($taille, PDO::PARAM_STR), ':ty' => array($type, PDO::PARAM_STR), ':d' => array($desc, PDO::PARAM_STR), ':b' => array($blob, PDO::PARAM_STR) )); } public function delete(int $id) { $query = 'DELETE FROM Image WHERE id=:i'; $this->con->executeQuery($query, array( ':i' => array($id, PDO::PARAM_INT) )); } public function findById(int $id) { $query = 'SELECT * FROM Image WHERE id=:i'; $this->con->executeQuery($query, array( ':i' => array($id, PDO::PARAM_INT) )); $res = $this->con->getResults(); return new Image($res[0]['nom'], $res[0]['desc'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']); } public function findByNom(string $nom) { $query = 'SELECT * FROM Image WHERE nom=:n'; $this->con->executeQuery($query, array( ':n' => array($nom, PDO::PARAM_STR) )); $res = $this->con->getResults(); return new Image($res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']); } public function getNewId() { $query = 'SELECT MAX(id) FROM Image'; $this->con->executeQuery($query); $res = $this->con->getResults(); return $res[0]['MAX(id)'] + 1; } public function getAll() { $query = 'SELECT * FROM Image'; $this->con->executeQuery($query); $res = $this->con->getResults(); $array = []; foreach ($res as $r) { $array[] = new Image($r['nom'], $r['taille'], $r['type'], $r['blob']); } return $array; } } ?>