Advertisement
Guest User

bases

a guest
Mar 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.35 KB | None | 0 0
  1. <?php
  2. class MYTABLE
  3. {
  4.     protected $_query;
  5.     protected $_resultatTd;
  6.     protected $_resultatTh;
  7.     protected $_tabColumn;
  8.     protected $_table;
  9.     protected $_dbh;
  10.     protected $_results;
  11.     protected $queryColumn;
  12.     protected $fields;
  13.  
  14.     function __construct($table)
  15.     {
  16.        
  17.         $this->_table = $table;
  18.         $this->_results = array();
  19.         try
  20.         {  
  21.             $this->_dbh = new PDO('mysql:host=localhost;dbname=restaurant;charset=utf8', 'root', '');
  22.         }
  23.         catch (PDOException $e)
  24.         {  
  25.             die( "Erreur ! : " . $e->getMessage() );
  26.         }
  27.         $queryTh = "SHOW COLUMNS FROM ".$table;
  28.        
  29.         $queryTd = "SELECT * FROM ".$table;
  30.        
  31.         $resultatTd = $this->_dbh->query($queryTd);
  32.         $resultatTh = $this->_dbh->query($queryTh);
  33.        
  34.         $this->_resultatTd = $resultatTd;
  35.         $this->_resultatTh = $resultatTh;
  36.         $fields = $this->_resultatTd->columnCount();
  37.         $this->fields = $fields;
  38.         // Fermeture de la connexion
  39.             //$dbh = NULL;
  40.     }  
  41.         public function getResultTd()
  42.         {
  43.             return $this->_resultatTd;                    
  44.         }
  45.         public function getResultTh()
  46.         {
  47.             return $this->_resultatTh;
  48.         }
  49.         public function INFO_TABLE()
  50.         {   //$compteurligne=0;
  51.             //$results = array();
  52.             //$result = ;
  53.             //while($ligne = $this->_resultatTh->fetch())
  54.             //{
  55.             //    $results[$compteurligne] = $ligne[0];
  56.                
  57.             //    $compteurligne++;
  58.             //}
  59.           //return $results;
  60.           $col = array();
  61.           for($i = 0; $i < $this->fields; $i++)
  62.           {
  63.               $col[$i] = $this->_resultatTd->getColumnMeta($i);
  64.           }
  65.              
  66.             return $col;
  67.         }
  68.         public function AJOUTER_DONNEES($nom, $adresse, $prix, $commentaire, $note, $visite){
  69.            
  70.             $requeteUpdate = "INSERT INTO ".$this->_table." VALUES(':nom', ':adresse', ':prix', ':commentaire', ':note', ':visite')";
  71.             $req = $this->_dbh->prepare($requeteUpdate);
  72.            
  73.             $req->bindParam(':nom', $nom, PDO::PARAM_STR);
  74.             $req->bindParam(':adresse', $adresse, PDO::PARAM_STR);
  75.             $req->bindParam(':prix', $prix, PDO::PARAM_STR);
  76.             $req->bindParam(':commentaire', $commentaire, PDO::PARAM_STR);
  77.             $req->bindParam(':note', $note, PDO::PARAM_INT);
  78.             $req->bindParam(':visite', $visite, PDO::PARAM_STR);
  79.            
  80.            
  81.             $bool_req = $req->execute();
  82.             return $bool_req;
  83.         }
  84.         public function UPDATE_DONNEES($id, $nom, $adresse, $prix, $commentaire, $note, $visite)
  85.         {
  86.             $requeteUpdate = "UPDATE ".$this->_table." SET nom = ".$nom.", adresse = ".$adresse.", prix = ".$prix.", commentaire = ".$commentaire.", note = ".$note.", visite =".$visite." WHERE id = ".$id;
  87.             $nb_req = $this->_dbh->exec($requeteUpdate);
  88.             if($nb_req == 0)
  89.             {
  90.                 echo'<h3>Edition du restaurant numéro : '.$id.'non effectuee</h3>';
  91.             }
  92.             else
  93.             {
  94.                 echo'Edition du restaurant numéro : '.$id.' effectuee';
  95.             }
  96.         }
  97.         public function UPDATE_DONNEES_PREP1($id, $nom, $adresse, $prix, $commentaire, $note, $visite)
  98.         {
  99.  
  100.  
  101.  
  102.             $requeteUpdate = "UPDATE ".$this->_table." SET nom = ?, adresse = ?, prix = ?, commentaire = ?, note = ?, visite = ?  WHERE id = ?";
  103.             $req = $this->_dbh->prepare($requeteUpdate);
  104.             $res = $req->execute(array($nom, $adresse, $prix, $commentaire, $note, $visite, $id));
  105.             echo var_dump($res);
  106.             if($res != TRUE)
  107.             {
  108.                 echo'<h3>Edition du restaurant numéro : '.$id.'non effectuee</h3>';
  109.             }
  110.             else
  111.             {
  112.                 echo'Edition du restaurant numéro : '.$id.' effectuee';
  113.             }
  114.         }
  115.         public function UPDATE_DONNEES_PREP2($id, $nom, $adresse, $prix, $commentaire, $note, $visite)
  116.         {
  117.  
  118.  
  119.  
  120.             $requeteUpdate = "UPDATE ".$this->_table." SET nom = :nom, adresse = :adresse, prix = :prix, commentaire = :commentaire, note = :note, visite = :visite  WHERE id = :id";
  121.             $req = $this->_dbh->prepare($requeteUpdate);
  122.             $req->bindParam(':id', $id, PDO::PARAM_INT);
  123.             $req->bindParam(':nom', $nom, PDO::PARAM_STR);
  124.             $req->bindParam(':adresse', $adresse, PDO::PARAM_STR);
  125.             $req->bindParam(':prix', $prix, PDO::PARAM_INT);
  126.             $req->bindParam(':commentaire', $commentaire, PDO::PARAM_STR);
  127.             $req->bindParam(':note', $note, PDO::PARAM_INT);
  128.             $req->bindParam(':visite', $visite, PDO::PARAM_STR);
  129.  
  130.             $res = $req->execute();
  131.            
  132.             if($res != TRUE)
  133.             {
  134.                 echo'<h3>Edition du restaurant numéro : '.$id.'non effectuee</h3>';
  135.             }
  136.             else
  137.             {
  138.                 echo'Edition du restaurant numéro : '.$id.' effectuee';
  139.             }
  140.         }
  141.         public function ADDUSER($user, $pass, $level)
  142.         {
  143.             $rq= "INSERT INTO ".$this->_table."(login, password, niveau) VALUES(:user, :pass, :niveau)";
  144.            
  145.             $pr = $this->_dbh->prepare($rq);
  146.             $pr->bindParam(':user', $user, PDO::PARAM_STR);
  147.             $pr->bindParam(':pass', $pass, PDO::PARAM_STR);
  148.             $pr->bindParam('niveau', $level, PDO::PARAM_STR);
  149.             $adduser = $pr->execute();
  150.             return $adduser;
  151.         }
  152.         public function DELETE($id)
  153.         {
  154.             $requete = "DELETE FROM ".$this->_table." WHERE id = $id";
  155.            
  156.            
  157.             $nb_req = $this->_dbh->exec($requete);
  158.             return $nb_req;
  159.         }
  160.         public function SelectByID($id)
  161.         {
  162.             $tab_donnees = array();
  163.             $rq="SELECT * FROM ".$this->_table." WHERE ID = ".$id;
  164.            
  165.             $donnees = $this->_dbh->query($rq);
  166.             $row = $donnees->fetch(PDO::FETCH_NUM);
  167.            
  168.             for ($i = 0; $i < count($row); $i++)
  169.             {
  170.                 $tab_donnees[$i] = $row[$i];
  171.             }
  172.             return $tab_donnees;
  173.         }
  174.         public function SEARCH_LOGIN($login, $pass)
  175.         {
  176.             $data = array();
  177.             $rq = "SELECT * FROM ".$this->_table." WHERE login = :login";
  178.             $req = $this->_dbh->prepare($rq);
  179.             $req->bindParam(':login', $login, PDO::PARAM_STR);
  180.            
  181.             $res = $req->execute();
  182.             $data = $req->fetch(PDO::FETCH_ASSOC);
  183.            
  184.             if(!password_verify($pass, $data['password']))
  185.             {
  186.                 return $data= NULL;
  187.             }
  188.             return $data;
  189.            
  190.             //$count = $req->rowCount();
  191.            
  192.            
  193.            
  194.         }
  195.         public function SEARCH_PASSWORD($login, $password)
  196.         {
  197.             $rq = "SELECT * FROM user WHERE login = :login AND password = :password";
  198.         }
  199.         public function SEARCH_LOGIN_DOUBLE($login)
  200.         {
  201.             $req = "SELECT login FROM user WHERE login = :login";
  202.             $stmt = $this->_dbh->prepare($req);
  203.             $stmt->bindParam(':login', $login, PDO::PARAM_STR);
  204.             $res = $stmt->execute();
  205.             if(($stmt->fetch(PDO::FETCH_ASSOC))['login']==$login)
  206.                 return FALSE;
  207.             else
  208.                 return TRUE;
  209.            
  210.                
  211.            
  212.         }
  213.         public function RENDRE_HTML()
  214.         {
  215.            
  216.             $montab=$this->INFO_TABLE();
  217.            
  218.             echo'<table class="table table-striped table-dark table-bordered">';
  219.             echo'<tr>';
  220.                     //for ($i = 0; $i < count($montab); $i++)
  221.                     //{
  222.                         //echo '<th>'.utf8_encode($montab[$i]).'</th>';
  223.                     //}
  224.                    for ($i=0; $i < $this->fields; $i++)
  225.                    {
  226.                        echo'<th>'.$montab[$i]['name'].'</th>';
  227.                    }
  228.                 echo'</tr>';
  229.             while($row = $this->_resultatTd->fetch())
  230.             {
  231.                 //echo'<tr><th style="font-size: 20px;">'.$row['id'].'</th>';
  232.                 for($i = 0; $i<count($montab); $i++)
  233.                 {
  234.                     //if(count($montab['flags']) == 2)
  235.                     //{
  236.                         //if($montab[$flags][1] == 'primary_key')
  237.                         //{
  238.                             //echo'<td>'.$montab[].'</td>';
  239.                         //}
  240.                         //echo'<td>'.$montab[$i]['flags'][2].'</td>';
  241.                     //}
  242.                     echo'<td>'.$row[$i].'</td>';
  243.                 }
  244.                
  245.                 //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>';
  246.                 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>';
  247.                 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>';
  248.                 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>';
  249.  
  250.                echo'</th></tr>';
  251.             }
  252.             echo'</table>';
  253.  
  254.            
  255.         }
  256.    
  257.    
  258. }
  259. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement