Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php
  2. /**
  3. * Description of mysql_DB
  4. *
  5. * @author Lakicevic
  6. */
  7. class mysql_DB {
  8. private $host;
  9. private $username;
  10. private $password;
  11. private $database;
  12.  
  13. private $conn;
  14.  
  15. public function __construct($database, $host = 'localhost', $username = 'root', $password = '') {
  16. $this->host = $host;
  17. $this->username = $username;
  18. $this->password = $password;
  19. $this->database = $database;
  20. }
  21.  
  22. public function connect(){
  23. $connString = 'mysql:host='.$this->host.';';
  24. $connString .= 'dbname = '.$this->database;
  25. try{
  26. $this->conn = new PDO($connString, $this->username, $this->password);
  27. }
  28. catch(PDOException $e){
  29. echo 'Error : '.$e->getMessage();
  30. }
  31. }
  32.  
  33. public function execute($query){
  34. try{
  35. $pdo_statement = $this->conn->query($query);
  36. return $pdo_statement->fetchAll(PDO::FETCH_ASSOC);
  37. }
  38. catch(PDOException $e){
  39. echo 'Error : '.$e->getMessage();
  40. return false;
  41. }
  42. }
  43.  
  44. public function __destruct() {
  45. $this->host = null;
  46. $this->username = null;
  47. $this->password = null;
  48. $this->database = null;
  49. $this->conn = null;
  50. }
  51. }
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement