Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.17 KB | None | 0 0
  1. <?php
  2.  
  3. class MySQL
  4. {
  5.  
  6.     //Attributes
  7.     private static $_connection;
  8.     private static $_host;
  9.     private static $_user;
  10.     private static $_pass;
  11.     private static $_bdd;
  12.     private static $_mySQL;
  13.  
  14.     // Properties
  15.     public function GetHost()
  16.     {
  17.         return(self::$_host);
  18.     }
  19.  
  20.     public function GetUser()
  21.     {
  22.         return(self::$_user);
  23.     }
  24.  
  25.     public function GetPass()
  26.     {
  27.         return(self::$_pass);
  28.     }
  29.  
  30.     // Constructor
  31.     private function __construct($host, $user, $pass, $BDDName)
  32.     {
  33.         self::InitConMySQL($host, $user, $pass, $BDDName);
  34.     }
  35.  
  36.     // Methods
  37.     public static function GetMySQLConnection($host, $user, $pass, $BDDName)
  38.     {
  39.         if (!isset(self::$_mySQL))
  40.         {
  41.             self::$_mySQL = new MySQL($host, $user, $pass, $BDDName);
  42.         }
  43.         return(self::$_mySQL);
  44.     }
  45.  
  46.     private static function InitConMySQL($host, $user, $pass, $BDDName)
  47.     {
  48.         try
  49.         {
  50.             self::$_connection = new PDO("mysql:host=$host;dbname=$BDDName",$user,$pass);
  51.  
  52.             //self::$_connection = mysqli_connect($host, $user, $pass);
  53.             self::$_host = $host;
  54.             self::$_user = $user;
  55.             self::$_pass = $pass;
  56.             self::$_bdd = $BDDName;
  57.         }
  58.         catch (PDOException $e)
  59.         {
  60.             echo $e->getMessage();
  61.         }
  62.     }
  63.  
  64. //    public function BDDConnect($BDDName)
  65. //    {
  66. //        mysqli_select_db(self::$_connection, $BDDName) or die(strval(mysqli_error()));
  67. //    }
  68. //
  69. //    public function BDDDeconnect()
  70. //    {
  71. //        mysqli_close(self::$_connection);
  72. //    }
  73.  
  74.     public function SendDisplayQuery($myQuery)
  75.     {
  76.         $my_query_substr = substr($myQuery, 5, 7);
  77.         //$query = mysqli_query(self::$_connection, $myQuery) or die('Requête : ' . $myQuery . ' - Error : ' . strval(mysqli_error()));
  78.         $stmt = self::$_connection->query($myQuery);
  79.         //die($my_query_substr);
  80.         //die($myQuery);
  81.         if ($my_query_substr == 'Display')
  82.         {
  83.             $tab = array();
  84.             $i = 0;
  85.  
  86.             while ($obj = $stmt->fetch(PDO::FETCH_OBJ))/*Remplissage du tableau d'objet(s)*/
  87.             {
  88.                 $tab[$i] = $obj;
  89.                 $i++;
  90.             }
  91.             //mysqli_free_result($query); /* Libere la memoire de la requête */
  92.             //die("<pre>".serialize($tab)."</pre>");
  93.             return($tab);
  94.         }
  95.     }
  96.  
  97.     public function SendInsertPressQuery($IDPRESS , $TITLE, $PLACE, $CONTENT)
  98.     {//die ($TITLE.$PLACE);
  99.         $stmt = self::$_connection->prepare("CALL EditPress(?,?,?,?)");
  100.         $stmt->bindParam(1, $IDPRESS, PDO::PARAM_INT/*, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000*/);
  101.         $stmt->bindParam(2, stripslashes($TITLE));
  102.         $stmt->bindParam(3, stripslashes($PLACE));
  103.         $stmt->bindParam(4, stripslashes($CONTENT));
  104.  
  105.         // appel de la procédure stockée
  106.         $stmt->execute();
  107.     }
  108.  
  109.     public function SendAddPressQuery($TypePress, $IdAuthor, $date, $place, $title, $content, $state)
  110.     {
  111.         $stmt = self::$_connection->prepare("CALL AddPress(?,?,?,?,?,?,?)");
  112.         $stmt->bindParam(1, $TypePress/*, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000*/);
  113.         $stmt->bindParam(2, $IdAuthor, PDO::PARAM_INT);
  114.         $stmt->bindParam(3, $date);
  115.         $stmt->bindParam(4, stripslashes($place));
  116.         $stmt->bindParam(5, stripslashes($title));
  117.         $stmt->bindParam(6, stripslashes($content));
  118.         $stmt->bindParam(7, $state, PDO::PARAM_INT);
  119.  
  120.         // appel de la procédure stockée
  121.         $stmt->execute();
  122.     }
  123.  
  124.     public function SendUpdateState($id, $state)
  125.     {
  126.         $stmt = self::$_connection->prepare("CALL ChangeStatePress(?,?)");
  127.         $stmt->bindParam(1, $id, PDO::PARAM_INT);
  128.         $stmt->bindParam(2, $state, PDO::PARAM_INT);
  129.         //die($id. ' '. $state);
  130.         $stmt->execute();
  131.     }
  132.  
  133.     public function deleteSelectedStaff($id)
  134.     {
  135.         $stmt = self::$_connection->prepare("CALL deleteSelectedStaff(?)");
  136.         $stmt->bindParam(1, $id, PDO::PARAM_INT);
  137.  
  138.         // appel de la procédure stockée
  139.         $stmt->execute();
  140.     }
  141.  
  142.     public function SendAddStaffQuery($idQuality, $nom, $prenom, $adresse, $cp, $ville, $tel, $email, $poste, $fax)
  143.     {
  144.         $stmt = self::$_connection->prepare("CALL AddStaff(?,?,?,?,?,?,?,?,?,?)");
  145.         $stmt->bindParam(1, $idQuality, PDO::PARAM_INT);
  146.         $stmt->bindParam(2, $nom);
  147.         $stmt->bindParam(3, $prenom);
  148.         $stmt->bindParam(4, $adresse);
  149.         $stmt->bindParam(5, $cp);
  150.         $stmt->bindParam(6, stripslashes($ville));
  151.         $stmt->bindParam(7, $tel, PDO::PARAM_INT);
  152.         $stmt->bindParam(8, $email);
  153.         $stmt->bindParam(9, $poste);
  154.         $stmt->bindParam(10, $fax);
  155.  
  156.         // appel de la procédure stockée
  157.         $stmt->execute();
  158.     }
  159.  
  160.     public function SendAlterStaffQuery($id, $idQuality, $nom, $prenom, $adresse, $cp, $ville, $poste, $fax, $tel, $email)
  161.     {
  162.         $stmt = self::$_connection->prepare("CALL AlterStaff(?,?,?,?,?,?,?,?,?,?,?)");
  163.         $stmt->bindParam(1, $id, PDO::PARAM_INT);
  164.         $stmt->bindParam(2, $idQuality, PDO::PARAM_INT);
  165.         $stmt->bindParam(3, $nom);
  166.         $stmt->bindParam(4, $prenom);
  167.         $stmt->bindParam(5, $adresse);
  168.         $stmt->bindParam(6, $cp);
  169.         $stmt->bindParam(7, stripslashes($ville));
  170.         $stmt->bindParam(8, $tel, PDO::PARAM_INT);
  171.         $stmt->bindParam(9, $email);
  172.         $stmt->bindParam(10, $poste);
  173.         $stmt->bindParam(11, $fax);
  174.  
  175.         // appel de la procédure stockée
  176.         $stmt->execute();
  177.     }
  178.  
  179.     public function SendUpdateStateStaff($id, $state)
  180.     {
  181.         //die($id . ' ' . $state);
  182.         $stmt = self::$_connection->prepare("CALL ChangeStateStaff(?,?)");
  183.         $stmt->bindParam(1, $id, PDO::PARAM_INT);
  184.         $stmt->bindParam(2, $state, PDO::PARAM_INT);
  185.         //die($id. ' '. $state);
  186.         $stmt->execute();
  187.     }
  188.  
  189.     public function __toString()
  190.     {
  191.         return('<font color="Blue">Server : </font>' . self::$_host . ' User : ' . self::$_user . ' Password : ' . self::$_pass);
  192.     }
  193.  
  194. }
  195. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement