Advertisement
Guest User

Untitled

a guest
May 12th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. class MySQL{
  2.  
  3. private $db_host;
  4. private $db_name;
  5. private $db_user;
  6. private $db_password;
  7. private $db_charset;
  8.  
  9. public function __construct($host, $name, $user, $password, $charset)
  10. {
  11. $this->db_host = $host;
  12. $this->db_name = $name;
  13. $this->db_user = $user;
  14. $this->db_password = $password;
  15. $this->db_charset = $charset;
  16. }
  17.  
  18. private function getPDO()
  19. {
  20. try {
  21. $pdo = new PDO('mysql:host=' . $this->db_host . ';dbname=' . $this->db_name . ';charset=' . $this->db_charset . '', '' . $this->db_user . '', '' . $this->db_password . '');
  22. } catch (Exception $e) {
  23. die('Erreur : ' . $e->getMessage());
  24. }
  25. return $pdo;
  26. }
  27.  
  28. public function getQuery($statement, $fetch = null, $class_name = null)
  29. {
  30. $req = $this->getPDO->query($statement);
  31.  
  32.  
  33. if ($class_name === null) {
  34. $req->setFetchMode(PDO::FETCH_OBJ);
  35. } else {
  36. $req->setFetchMode(PDO::FETCH_CLASS, $class_name);
  37. }
  38.  
  39. if ($fetch === fetch) {
  40. $datas = $req->fetch();
  41. } else {
  42. $datas = $req->fetchAll();
  43. }
  44. return $datas;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement