Advertisement
Guest User

dbclassphp

a guest
Jun 19th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <?php
  2. class dbclass
  3. {
  4. private $username ;
  5. private $password ;
  6. private $dsn;
  7. private $conn;
  8. public function __construct(){
  9. $this->username = "root";
  10. $this->password = "";
  11. $this->dsn = "mysql:host=localhost;dbname=db_coba";
  12. }
  13. public function openConnection(){
  14. try{
  15. $this->conn = new PDO($this->dsn,$this->username,$this->password) ;
  16. $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  17. echo 'Connection Success'."\n";
  18. return $this->conn;
  19. }
  20. catch(PDOException $e){
  21. echo 'Connection failed'."\n";
  22. }
  23.  
  24. }
  25. public function closeConnection(){
  26. $this->conn = null;
  27. echo 'Connection closed'."\n";
  28. }
  29. }
  30.  
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement