Advertisement
Guest User

Untitled

a guest
Dec 1st, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. Ashik Rafat:
  2. <?php
  3. class Database{
  4.  
  5. // specify your own database credentials
  6. private $host = "localhost";
  7. private $db_name = "APIDB";
  8. private $username = "root";
  9. private $password = "";
  10. public $conn;
  11.  
  12. // get the database connection
  13. public function getConnection(){
  14.  
  15. $this->conn = null;
  16.  
  17. try{
  18. $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
  19. $this->conn->exec("set names utf8");
  20. }catch(PDOException $exception){
  21. echo "Connection error: " . $exception->getMessage();
  22. }
  23.  
  24. return $this->conn;
  25.  
  26. }
  27. }
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement