Last active
April 8, 2019 12:09
-
-
Save vishaldodiya/dfde46e263e35fac7763815262ad4534 to your computer and use it in GitHub Desktop.
PHP Abstract Class Example
This file contains hidden or 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 Db | |
{ | |
protected $pdo; | |
public function __construct($pdo) | |
{ | |
$this->pdo = $pdo; | |
} | |
abstract function select($table, $fields); | |
} | |
class Db_Mysql extends Db | |
{ | |
public function select($table, $fields) | |
{ | |
// Build MySQL specific select query | |
// then execute it with $this->pdo | |
} | |
} | |
class Db_Pgsql extends Db | |
{ | |
public function select($table, $fields) | |
{ | |
// Build PostgreSQL specific select query | |
// then execute it with $this->pdo | |
} | |
} | |
// Usage: | |
$db = new Db_Mysql($pdo); | |
$db->select('users', array('id', 'name')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment