Last active
August 29, 2015 14:05
-
-
Save khamer/915eb76b09a31b6dc16f to your computer and use it in GitHub Desktop.
Example of a Static Class
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 | |
| class ExampleDatabase { | |
| static private $db = null; | |
| static public function connect($connection_string) | |
| { | |
| return self::$db = pg_connect($connection_string); | |
| } | |
| static public function query($query) | |
| { | |
| return pg_query(self::$db, $query); | |
| } | |
| } | |
| /* configuration */ | |
| ExampleDatabase::connect('dbname=testing'); | |
| /* usage */ | |
| $result = ExampleDatabase::query('SELECT * FROM users'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment