Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MYTABLE
- {
- protected $_query;
- protected $_resultatTd;
- protected $_resultatTh;
- protected $_tabColumn;
- protected $_table;
- protected $_dbh;
- protected $_results;
- protected $queryColumn;
- protected $fields;
- function __construct($table)
- {
- $this->_table = $table;
- $this->_results = array();
- try
- {
- $this->_dbh = new PDO('mysql:host=localhost;dbname=restaurant;charset=utf8', 'root', '');
- }
- catch (PDOException $e)
- {
- die( "Erreur ! : " . $e->getMessage() );
- }
- $queryTh = "SHOW COLUMNS FROM ".$table;
- $queryTd = "SELECT * FROM ".$table;
- $resultatTd = $this->_dbh->query($queryTd);
- $resultatTh = $this->_dbh->query($queryTh);
- $this->_resultatTd = $resultatTd;
- $this->_resultatTh = $resultatTh;
- $fields = $this->_resultatTd->columnCount();
- $this->fields = $fields;
- // Fermeture de la connexion
- //$dbh = NULL;
- }
- public function getResultTd()
- {
- return $this->_resultatTd;
- }
- public function getResultTh()
- {
- return $this->_resultatTh;
- }
- public function INFO_TABLE()
- { //$compteurligne=0;
- //$results = array();
- //$result = ;
- //while($ligne = $this->_resultatTh->fetch())
- //{
- // $results[$compteurligne] = $ligne[0];
- // $compteurligne++;
- //}
- //return $results;
- $col = array();
- for($i = 0; $i < $this->fields; $i++)
- {
- $col[$i] = $this->_resultatTd->getColumnMeta($i);
- }
- return $col;
- }
- public function AJOUTER_DONNEES($nom, $adresse, $prix, $commentaire, $note, $visite){
- $requeteUpdate = "INSERT INTO ".$this->_table." VALUES(':nom', ':adresse', ':prix', ':commentaire', ':note', ':visite')";
- $req = $this->_dbh->prepare($requeteUpdate);
- $req->bindParam(':nom', $nom, PDO::PARAM_STR);
- $req->bindParam(':adresse', $adresse, PDO::PARAM_STR);
- $req->bindParam(':prix', $prix, PDO::PARAM_STR);
- $req->bindParam(':commentaire', $commentaire, PDO::PARAM_STR);
- $req->bindParam(':note', $note, PDO::PARAM_INT);
- $req->bindParam(':visite', $visite, PDO::PARAM_STR);
- $bool_req = $req->execute();
- return $bool_req;
- }
- public function UPDATE_DONNEES($id, $nom, $adresse, $prix, $commentaire, $note, $visite)
- {
- $requeteUpdate = "UPDATE ".$this->_table." SET nom = ".$nom.", adresse = ".$adresse.", prix = ".$prix.", commentaire = ".$commentaire.", note = ".$note.", visite =".$visite." WHERE id = ".$id;
- $nb_req = $this->_dbh->exec($requeteUpdate);
- if($nb_req == 0)
- {
- echo'<h3>Edition du restaurant numéro : '.$id.'non effectuee</h3>';
- }
- else
- {
- echo'Edition du restaurant numéro : '.$id.' effectuee';
- }
- }
- public function UPDATE_DONNEES_PREP1($id, $nom, $adresse, $prix, $commentaire, $note, $visite)
- {
- $requeteUpdate = "UPDATE ".$this->_table." SET nom = ?, adresse = ?, prix = ?, commentaire = ?, note = ?, visite = ? WHERE id = ?";
- $req = $this->_dbh->prepare($requeteUpdate);
- $res = $req->execute(array($nom, $adresse, $prix, $commentaire, $note, $visite, $id));
- echo var_dump($res);
- if($res != TRUE)
- {
- echo'<h3>Edition du restaurant numéro : '.$id.'non effectuee</h3>';
- }
- else
- {
- echo'Edition du restaurant numéro : '.$id.' effectuee';
- }
- }
- public function UPDATE_DONNEES_PREP2($id, $nom, $adresse, $prix, $commentaire, $note, $visite)
- {
- $requeteUpdate = "UPDATE ".$this->_table." SET nom = :nom, adresse = :adresse, prix = :prix, commentaire = :commentaire, note = :note, visite = :visite WHERE id = :id";
- $req = $this->_dbh->prepare($requeteUpdate);
- $req->bindParam(':id', $id, PDO::PARAM_INT);
- $req->bindParam(':nom', $nom, PDO::PARAM_STR);
- $req->bindParam(':adresse', $adresse, PDO::PARAM_STR);
- $req->bindParam(':prix', $prix, PDO::PARAM_INT);
- $req->bindParam(':commentaire', $commentaire, PDO::PARAM_STR);
- $req->bindParam(':note', $note, PDO::PARAM_INT);
- $req->bindParam(':visite', $visite, PDO::PARAM_STR);
- $res = $req->execute();
- if($res != TRUE)
- {
- echo'<h3>Edition du restaurant numéro : '.$id.'non effectuee</h3>';
- }
- else
- {
- echo'Edition du restaurant numéro : '.$id.' effectuee';
- }
- }
- public function ADDUSER($user, $pass, $level)
- {
- $rq= "INSERT INTO ".$this->_table."(login, password, niveau) VALUES(:user, :pass, :niveau)";
- $pr = $this->_dbh->prepare($rq);
- $pr->bindParam(':user', $user, PDO::PARAM_STR);
- $pr->bindParam(':pass', $pass, PDO::PARAM_STR);
- $pr->bindParam('niveau', $level, PDO::PARAM_STR);
- $adduser = $pr->execute();
- return $adduser;
- }
- public function DELETE($id)
- {
- $requete = "DELETE FROM ".$this->_table." WHERE id = $id";
- $nb_req = $this->_dbh->exec($requete);
- return $nb_req;
- }
- public function SelectByID($id)
- {
- $tab_donnees = array();
- $rq="SELECT * FROM ".$this->_table." WHERE ID = ".$id;
- $donnees = $this->_dbh->query($rq);
- $row = $donnees->fetch(PDO::FETCH_NUM);
- for ($i = 0; $i < count($row); $i++)
- {
- $tab_donnees[$i] = $row[$i];
- }
- return $tab_donnees;
- }
- public function SEARCH_LOGIN($login, $pass)
- {
- $data = array();
- $rq = "SELECT * FROM ".$this->_table." WHERE login = :login";
- $req = $this->_dbh->prepare($rq);
- $req->bindParam(':login', $login, PDO::PARAM_STR);
- $res = $req->execute();
- $data = $req->fetch(PDO::FETCH_ASSOC);
- if(!password_verify($pass, $data['password']))
- {
- return $data= NULL;
- }
- return $data;
- //$count = $req->rowCount();
- }
- public function SEARCH_PASSWORD($login, $password)
- {
- $rq = "SELECT * FROM user WHERE login = :login AND password = :password";
- }
- public function SEARCH_LOGIN_DOUBLE($login)
- {
- $req = "SELECT login FROM user WHERE login = :login";
- $stmt = $this->_dbh->prepare($req);
- $stmt->bindParam(':login', $login, PDO::PARAM_STR);
- $res = $stmt->execute();
- if(($stmt->fetch(PDO::FETCH_ASSOC))['login']==$login)
- return FALSE;
- else
- return TRUE;
- }
- public function RENDRE_HTML()
- {
- $montab=$this->INFO_TABLE();
- echo'<table class="table table-striped table-dark table-bordered">';
- echo'<tr>';
- //for ($i = 0; $i < count($montab); $i++)
- //{
- //echo '<th>'.utf8_encode($montab[$i]).'</th>';
- //}
- for ($i=0; $i < $this->fields; $i++)
- {
- echo'<th>'.$montab[$i]['name'].'</th>';
- }
- echo'</tr>';
- while($row = $this->_resultatTd->fetch())
- {
- //echo'<tr><th style="font-size: 20px;">'.$row['id'].'</th>';
- for($i = 0; $i<count($montab); $i++)
- {
- //if(count($montab['flags']) == 2)
- //{
- //if($montab[$flags][1] == 'primary_key')
- //{
- //echo'<td>'.$montab[].'</td>';
- //}
- //echo'<td>'.$montab[$i]['flags'][2].'</td>';
- //}
- echo'<td>'.$row[$i].'</td>';
- }
- //echo'<td><a href="modif_restaurant.php?edit='.$row['id'].'" class="btn btn-info">Edition</a></td><td><a href="guide_restaurant.php?delete='.$row['id'].'" name="delete" class="btn btn-danger">Effacer</a></td>';
- echo'<td><form action="detail_restaurant.php" method="post" name="form_detail"><input type="hidden" value="'.$row['id'].'" name="id_detail"><input type="submit" name="detail" value="Detail" class="btn btn-primary"></form></td>';
- echo'<td><form action="modif_restaurant.php" method="post" name="form_edit"><input type="hidden" value="'.$row['id'].'" name="id_edit"><input type="submit" name="edit" value="Edition" class="btn btn-info"></form></td>';
- echo'<td><form action="guide_restaurant.php" method="post" name="form_delete"><input type="hidden" value="'.$row['id'].'" name="id_delete"><input type="submit" name="delete" value="Supprimer" class="btn btn-danger"></form></td>';
- echo'</th></tr>';
- }
- echo'</table>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement