Created
March 22, 2019 13:45
-
-
Save mhmohon/8af26df5a9e9f27ddd097ca8e7b7f8c5 to your computer and use it in GitHub Desktop.
Using Abstract class and interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class DBCommonMethods //creating abstract class | |
{ | |
private $host; | |
private $db; | |
private $uid; | |
private $password; | |
public function __construct($host, $db, $uid, $password) | |
{ | |
$this->host = $host; | |
$this->db = $db; | |
$this->uid = $uid; | |
$this->password = $password; | |
} | |
} | |
interface DBInterface //create interface | |
{ | |
public function db_connect(); | |
public function insert($data); | |
public function read($where); | |
public function update($where); | |
public function delete($where); | |
} | |
class MySQLDriver extends DBCommonMethods implements DBInterface { | |
public function __construct($host, $db, $uid, $password) | |
{ | |
parent::__construct($host, $db, $uid, $password); | |
} | |
public function db_connect() { //connect code goes here } | |
public function delete($where) { //delete code goes here } | |
public function insert($data) { //insert code goes here } | |
public function read($where) { //read code goes here } | |
public function update($where) { //update code goes here } | |
} | |
?> | |
<?php $db = new MySQLDriver($host,$db,$uid,$password); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment