Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <?php
  2. class Database
  3. {
  4. private $host = "localhost";
  5. private $db_name = "namedb";
  6. private $username = "user";
  7. private $password = "password";
  8. public $conn;
  9.  
  10. public function dbConnection()
  11. {
  12.  
  13. $this->conn = null;
  14. try
  15. {
  16. $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
  17. $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  18. if($this->conn){
  19. echo "Connection success";
  20. }
  21. }
  22. catch(PDOException $exception)
  23. {
  24. echo "Connection error: " . $exception->getMessage();
  25. }
  26.  
  27. return $this->conn;
  28. }
  29.  
  30. }
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement