Skip to content

Instantly share code, notes, and snippets.

@vishaldodiya
Last active April 8, 2019 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishaldodiya/dfde46e263e35fac7763815262ad4534 to your computer and use it in GitHub Desktop.
Save vishaldodiya/dfde46e263e35fac7763815262ad4534 to your computer and use it in GitHub Desktop.
PHP Abstract Class Example
<?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