Skip to content

Instantly share code, notes, and snippets.

@mhmohon
Created March 22, 2019 13:45
Show Gist options
  • Save mhmohon/8af26df5a9e9f27ddd097ca8e7b7f8c5 to your computer and use it in GitHub Desktop.
Save mhmohon/8af26df5a9e9f27ddd097ca8e7b7f8c5 to your computer and use it in GitHub Desktop.
Using Abstract class and interface
<?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