Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MySQL
- {
- //Attributes
- private static $_connection;
- private static $_host;
- private static $_user;
- private static $_pass;
- private static $_bdd;
- private static $_mySQL;
- // Properties
- public function GetHost()
- {
- return(self::$_host);
- }
- public function GetUser()
- {
- return(self::$_user);
- }
- public function GetPass()
- {
- return(self::$_pass);
- }
- // Constructor
- private function __construct($host, $user, $pass, $BDDName)
- {
- self::InitConMySQL($host, $user, $pass, $BDDName);
- }
- // Methods
- public static function GetMySQLConnection($host, $user, $pass, $BDDName)
- {
- if (!isset(self::$_mySQL))
- {
- self::$_mySQL = new MySQL($host, $user, $pass, $BDDName);
- }
- return(self::$_mySQL);
- }
- private static function InitConMySQL($host, $user, $pass, $BDDName)
- {
- try
- {
- self::$_connection = new PDO("mysql:host=$host;dbname=$BDDName",$user,$pass);
- //self::$_connection = mysqli_connect($host, $user, $pass);
- self::$_host = $host;
- self::$_user = $user;
- self::$_pass = $pass;
- self::$_bdd = $BDDName;
- }
- catch (PDOException $e)
- {
- echo $e->getMessage();
- }
- }
- // public function BDDConnect($BDDName)
- // {
- // mysqli_select_db(self::$_connection, $BDDName) or die(strval(mysqli_error()));
- // }
- //
- // public function BDDDeconnect()
- // {
- // mysqli_close(self::$_connection);
- // }
- public function SendDisplayQuery($myQuery)
- {
- $my_query_substr = substr($myQuery, 5, 7);
- //$query = mysqli_query(self::$_connection, $myQuery) or die('Requête : ' . $myQuery . ' - Error : ' . strval(mysqli_error()));
- $stmt = self::$_connection->query($myQuery);
- //die($my_query_substr);
- //die($myQuery);
- if ($my_query_substr == 'Display')
- {
- $tab = array();
- $i = 0;
- while ($obj = $stmt->fetch(PDO::FETCH_OBJ))/*Remplissage du tableau d'objet(s)*/
- {
- $tab[$i] = $obj;
- $i++;
- }
- //mysqli_free_result($query); /* Libere la memoire de la requête */
- //die("<pre>".serialize($tab)."</pre>");
- return($tab);
- }
- }
- public function SendInsertPressQuery($IDPRESS , $TITLE, $PLACE, $CONTENT)
- {//die ($TITLE.$PLACE);
- $stmt = self::$_connection->prepare("CALL EditPress(?,?,?,?)");
- $stmt->bindParam(1, $IDPRESS, PDO::PARAM_INT/*, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000*/);
- $stmt->bindParam(2, stripslashes($TITLE));
- $stmt->bindParam(3, stripslashes($PLACE));
- $stmt->bindParam(4, stripslashes($CONTENT));
- // appel de la procédure stockée
- $stmt->execute();
- }
- public function SendAddPressQuery($TypePress, $IdAuthor, $date, $place, $title, $content, $state)
- {
- $stmt = self::$_connection->prepare("CALL AddPress(?,?,?,?,?,?,?)");
- $stmt->bindParam(1, $TypePress/*, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000*/);
- $stmt->bindParam(2, $IdAuthor, PDO::PARAM_INT);
- $stmt->bindParam(3, $date);
- $stmt->bindParam(4, stripslashes($place));
- $stmt->bindParam(5, stripslashes($title));
- $stmt->bindParam(6, stripslashes($content));
- $stmt->bindParam(7, $state, PDO::PARAM_INT);
- // appel de la procédure stockée
- $stmt->execute();
- }
- public function SendUpdateState($id, $state)
- {
- $stmt = self::$_connection->prepare("CALL ChangeStatePress(?,?)");
- $stmt->bindParam(1, $id, PDO::PARAM_INT);
- $stmt->bindParam(2, $state, PDO::PARAM_INT);
- //die($id. ' '. $state);
- $stmt->execute();
- }
- public function deleteSelectedStaff($id)
- {
- $stmt = self::$_connection->prepare("CALL deleteSelectedStaff(?)");
- $stmt->bindParam(1, $id, PDO::PARAM_INT);
- // appel de la procédure stockée
- $stmt->execute();
- }
- public function SendAddStaffQuery($idQuality, $nom, $prenom, $adresse, $cp, $ville, $tel, $email, $poste, $fax)
- {
- $stmt = self::$_connection->prepare("CALL AddStaff(?,?,?,?,?,?,?,?,?,?)");
- $stmt->bindParam(1, $idQuality, PDO::PARAM_INT);
- $stmt->bindParam(2, $nom);
- $stmt->bindParam(3, $prenom);
- $stmt->bindParam(4, $adresse);
- $stmt->bindParam(5, $cp);
- $stmt->bindParam(6, stripslashes($ville));
- $stmt->bindParam(7, $tel, PDO::PARAM_INT);
- $stmt->bindParam(8, $email);
- $stmt->bindParam(9, $poste);
- $stmt->bindParam(10, $fax);
- // appel de la procédure stockée
- $stmt->execute();
- }
- public function SendAlterStaffQuery($id, $idQuality, $nom, $prenom, $adresse, $cp, $ville, $poste, $fax, $tel, $email)
- {
- $stmt = self::$_connection->prepare("CALL AlterStaff(?,?,?,?,?,?,?,?,?,?,?)");
- $stmt->bindParam(1, $id, PDO::PARAM_INT);
- $stmt->bindParam(2, $idQuality, PDO::PARAM_INT);
- $stmt->bindParam(3, $nom);
- $stmt->bindParam(4, $prenom);
- $stmt->bindParam(5, $adresse);
- $stmt->bindParam(6, $cp);
- $stmt->bindParam(7, stripslashes($ville));
- $stmt->bindParam(8, $tel, PDO::PARAM_INT);
- $stmt->bindParam(9, $email);
- $stmt->bindParam(10, $poste);
- $stmt->bindParam(11, $fax);
- // appel de la procédure stockée
- $stmt->execute();
- }
- public function SendUpdateStateStaff($id, $state)
- {
- //die($id . ' ' . $state);
- $stmt = self::$_connection->prepare("CALL ChangeStateStaff(?,?)");
- $stmt->bindParam(1, $id, PDO::PARAM_INT);
- $stmt->bindParam(2, $state, PDO::PARAM_INT);
- //die($id. ' '. $state);
- $stmt->execute();
- }
- public function __toString()
- {
- return('<font color="Blue">Server : </font>' . self::$_host . ' User : ' . self::$_user . ' Password : ' . self::$_pass);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement