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/5643e5fa9b35ec7e4dc4 to your computer and use it in GitHub Desktop.

Select an option

Save khamer/5643e5fa9b35ec7e4dc4 to your computer and use it in GitHub Desktop.
Example using Dependency Injection
<?php
class ExampleDatabase {
private $db = null;
public function __construct($connection_string)
{
$this->db = pg_connect($connection_string);
}
public function query($query)
{
return pg_query($this->db, $query);
}
}
/* configuration */
$container = new Pimple\Container();
$container['database'] = function() {
return new ExampleDatabase('dbname=testing');
};
/* usage */
$example_db = $container['database'];
$result = $example_db->query('SELECT * FROM users');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment