From 9c9cda0ac823863c6760d77984ea2ecaf87c52ab Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 16 Jul 2024 05:04:13 +0200 Subject: =?UTF-8?q?renommage=20complet=20des=20ID=20en=20id:=20variables,?= =?UTF-8?q?=20m=C3=A9thodes,=20BDD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/Model.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/model/Model.php') diff --git a/src/model/Model.php b/src/model/Model.php index 9ada9a4..b3d157d 100644 --- a/src/model/Model.php +++ b/src/model/Model.php @@ -21,15 +21,15 @@ abstract class Model extends DB } // setters - public function setID(int $value = 0) + public function setId(int $value = 0) { if($value === 0) { - $this->ID = $this->db->lastInsertId(); // méthode de PDO, attention lastInsertId() ne gère pas la concurence + $this->id = $this->db->lastInsertId(); // méthode de PDO, attention lastInsertId() ne gère pas la concurence } else { - $this->ID = $value; + $this->id = $value; } return $this; } @@ -202,7 +202,7 @@ abstract class Model extends DB public function findById() // obtenir une entrée grace à son ID { - return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $this->ID)->fetch()); + return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $this->id)->fetch()); } public function getDetailsByIdPresta() { @@ -214,7 +214,7 @@ abstract class Model extends DB } else { - return $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id_Presta = ' . $this->ID_presta)->fetch(); // type array + return $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id_Presta = ' . $this->id_presta)->fetch(); // type array } } @@ -223,13 +223,13 @@ abstract class Model extends DB $fields = []; $values = []; - // change "'ID' => 2" en "'ID' = ?" et "2" + // change "'id' => 2" en "'id' = ?" et "2" foreach($criteria as $field => $value) { $fields[] = "$field = ?"; // même chose que: $field . " = ?" $values[] = $value; } - $field_list = implode(' AND ', $fields); // créer une chaîne reliant les morceaux avec le morceau AND en paramètre: 'adresse = ? AND ID = ?' + $field_list = implode(' AND ', $fields); // créer une chaîne reliant les morceaux avec le morceau AND en paramètre: 'adresse = ? AND id = ?' // SELECT * FROM annonces WHERE actif = 1; return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field_list, $values)->fetchAll()); @@ -252,7 +252,7 @@ abstract class Model extends DB $values[] = $value; } } - $values[] = $this->ID; // cette syntaxe ajoute une valeur au tableau + $values[] = $this->id; // cette syntaxe ajoute une valeur au tableau $field_list = implode(', ', $fields); // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id = ? @@ -261,7 +261,7 @@ abstract class Model extends DB public function updateOneValue(string $field, $value) { - return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field . ' = ? WHERE id = ?', [$value, $this->ID])); + return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field . ' = ? WHERE id = ?', [$value, $this->id])); } -- cgit v1.2.3