Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class dbclass
- {
- private $username ;
- private $password ;
- private $dsn;
- private $conn;
- public function __construct(){
- $this->username = "root";
- $this->password = "";
- $this->dsn = "mysql:host=localhost;dbname=db_coba";
- }
- public function openConnection(){
- try{
- $this->conn = new PDO($this->dsn,$this->username,$this->password) ;
- $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- echo 'Connection Success'."\n";
- return $this->conn;
- }
- catch(PDOException $e){
- echo 'Connection failed'."\n";
- }
- }
- public function closeConnection(){
- $this->conn = null;
- echo 'Connection closed'."\n";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement