Advertisement
Guest User

Untitled

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