@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace core; |
| 3 | 3 | |
| 4 | - use core\HTML\flashmessage\FlashMessage; |
|
| 4 | + use core\HTML\flashmessage\FlashMessage; |
|
| 5 | 5 | use PDO; |
| 6 | 6 | |
| 7 | 7 | class Database {
|
@@ -4,7 +4,7 @@ |
||
| 4 | 4 | use core\HTML\flashmessage\FlashMessage; |
| 5 | 5 | use PDO; |
| 6 | 6 | |
| 7 | - class Database extends Querybuilder{
|
|
| 7 | + class Database extends Querybuilder {
|
|
| 8 | 8 | private $db_type; |
| 9 | 9 | private $db_name; |
| 10 | 10 | private $db_user; |
@@ -53,8 +53,7 @@ discard block |
||
| 53 | 53 | if ($query) {
|
| 54 | 54 | $obj = $query->fetchAll(PDO::FETCH_OBJ); |
| 55 | 55 | return $obj; |
| 56 | - } |
|
| 57 | - else {
|
|
| 56 | + } else {
|
|
| 58 | 57 | FlashMessage::setFlash("Une erreur est survenue en executant cette requette : ".$req);
|
| 59 | 58 | } |
| 60 | 59 | } |
@@ -73,8 +72,7 @@ discard block |
||
| 73 | 72 | $err = true; |
| 74 | 73 | } |
| 75 | 74 | } |
| 76 | - } |
|
| 77 | - else {
|
|
| 75 | + } else {
|
|
| 78 | 76 | if (!$query->execute($value)) {
|
| 79 | 77 | $err = true; |
| 80 | 78 | } |
@@ -96,8 +94,7 @@ discard block |
||
| 96 | 94 | public function rechercherEgalite($table, $champ, $value, $id_table = null, $id = null) {
|
| 97 | 95 | if ($id == null) {
|
| 98 | 96 | $query = $this->getPdo()->query("SELECT COUNT($champ) as nb FROM $table WHERE $champ LIKE '$value'");
|
| 99 | - } |
|
| 100 | - else {
|
|
| 97 | + } else {
|
|
| 101 | 98 | $query = $this->getPdo()->query("SELECT COUNT($champ) as nb FROM $table WHERE $champ LIKE '$value' AND $id_table != $id");
|
| 102 | 99 | } |
| 103 | 100 | |
@@ -106,9 +103,10 @@ discard block |
||
| 106 | 103 | $nb = $obj["nb"]; |
| 107 | 104 | } |
| 108 | 105 | |
| 109 | - if ((isset($nb)) && ($nb != 0)) return true; |
|
| 110 | - } |
|
| 111 | - else {
|
|
| 106 | + if ((isset($nb)) && ($nb != 0)) { |
|
| 107 | + return true; |
|
| 108 | + } |
|
| 109 | + } else {
|
|
| 112 | 110 | return false; |
| 113 | 111 | } |
| 114 | 112 | } |
@@ -125,8 +123,7 @@ discard block |
||
| 125 | 123 | |
| 126 | 124 | if ($query->rowCount() > 0) {
|
| 127 | 125 | return true; |
| 128 | - } |
|
| 129 | - else {
|
|
| 126 | + } else {
|
|
| 130 | 127 | return false; |
| 131 | 128 | } |
| 132 | 129 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * pour intialiser la ou les clauses where d'une requete |
| 249 | 249 | */ |
| 250 | 250 | public function where($champ, $cond, $champ_test, $closure = null) {
|
| 251 | - if ( $closure === null) {
|
|
| 251 | + if ($closure === null) {
|
|
| 252 | 252 | $this->conditions[] = $champ.$cond.$champ_test; |
| 253 | 253 | } |
| 254 | 254 | else {
|
@@ -264,10 +264,10 @@ discard block |
||
| 264 | 264 | * fonction qui permet de récupérer un select fait sur une table |
| 265 | 265 | */ |
| 266 | 266 | public function get() {
|
| 267 | - $requete = $this->req_beginning . implode(",", $this->champs) . " FROM " . implode(",", $this->table);
|
|
| 267 | + $requete = $this->req_beginning.implode(",", $this->champs)." FROM ".implode(",", $this->table);
|
|
| 268 | 268 | |
| 269 | 269 | if (!empty($this->conditions)) {
|
| 270 | - $requete .= " WHERE ". implode(" ", $this->conditions);
|
|
| 270 | + $requete .= " WHERE ".implode(" ", $this->conditions);
|
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | $this->unsetQueryBuilder(); |
@@ -282,15 +282,15 @@ discard block |
||
| 282 | 282 | |
| 283 | 283 | $datas = []; |
| 284 | 284 | $count = count($this->champs); |
| 285 | - for ($i=0 ; $i<$count ; $i++) {
|
|
| 285 | + for ($i = 0; $i < $count; $i++) {
|
|
| 286 | 286 | $datas[] = $this->champs[$i]."=:".$this->champs[$i]; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | //si on a des conditions alors on sera dans un insert |
| 290 | - $requete = $this->req_beginning . implode(",", $this->table) . " SET " . implode(", ", $datas);
|
|
| 290 | + $requete = $this->req_beginning.implode(",", $this->table)." SET ".implode(", ", $datas);
|
|
| 291 | 291 | |
| 292 | 292 | if (!empty($this->conditions)) {
|
| 293 | - $requete .= " WHERE " . implode(" ", $this->conditions);
|
|
| 293 | + $requete .= " WHERE ".implode(" ", $this->conditions);
|
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | $this->prepare($requete, $values); |
@@ -301,10 +301,10 @@ discard block |
||
| 301 | 301 | * fonction utilisée pour finir un delete |
| 302 | 302 | */ |
| 303 | 303 | public function del() {
|
| 304 | - $requete = $this->req_beginning . implode(",", $this->table);
|
|
| 304 | + $requete = $this->req_beginning.implode(",", $this->table);
|
|
| 305 | 305 | |
| 306 | 306 | if (!empty($this->conditions)) {
|
| 307 | - $requete .= " WHERE " . implode(" ", $this->conditions);
|
|
| 307 | + $requete .= " WHERE ".implode(" ", $this->conditions);
|
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | $this->query($requete); |
@@ -110,8 +110,7 @@ |
||
| 110 | 110 | public function where($champ, $cond, $champ_test, $closure = null) {
|
| 111 | 111 | if ( $closure === null) {
|
| 112 | 112 | $this->conditions[] = $champ.$cond.$champ_test; |
| 113 | - } |
|
| 114 | - else {
|
|
| 113 | + } else {
|
|
| 115 | 114 | $this->conditions[] = $champ.$cond.$champ_test." ".$closure; |
| 116 | 115 | } |
| 117 | 116 | |