Advertisement
Yousuf1791

Book-page-167

Aug 7th, 2022
926
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. <?php
  2. abstract class Database{
  3.     static public $connection;
  4.     static public function getConnectionCount(){
  5.         echo "<br>Current connection : ". self::$connection ;
  6.     }
  7.  
  8.     static public function increaseCount(){
  9.         self::$connection++ ;
  10.     }
  11.  
  12.     abstract public function connect();
  13. }
  14.  
  15. class MySQL extends Database{
  16.     public function connect(){ //implement connect
  17.         Database::increaseCount(); //access static method
  18.         echo "<br>Connect to MySQL";
  19.     }
  20.  
  21.     public function save(){
  22.         echo "<br>Save to Database";
  23.     }
  24. }
  25.  
  26. $mysql = new MySQL();
  27. $mysql->connect();
  28. $mysql->save();
  29.  
  30. Database::getConnectionCount(); //access static method
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement