Skip to content

Instantly share code, notes, and snippets.

@khamer
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save khamer/915eb76b09a31b6dc16f to your computer and use it in GitHub Desktop.

Select an option

Save khamer/915eb76b09a31b6dc16f to your computer and use it in GitHub Desktop.
Example of a Static Class
<?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