Skip to content

Instantly share code, notes, and snippets.

@chanmix51
Last active October 1, 2015 13:37
Show Gist options
  • Save chanmix51/2000890 to your computer and use it in GitHub Desktop.
Save chanmix51/2000890 to your computer and use it in GitHub Desktop.
Fetching data with Pomm
<?php
use Pomm\Connection\Database;
$loader = require __DIR__."/vendor/.composer/autoload.php";
$loader->add('YourDb', __DIR__."/model");
$database = new Database(array('dsn' => 'pgsql://user:pass@host:port/your_db'));
$book = $database
->getConnection()
->getMapFor('YourDb\Test\Book')
->findByPk(array('id' => 1));
print_r($book);
Table "test.book"
Column | Type | Modifiers
-----------------+-----------------------------+---------------------------------------------------
id | integer | not null default nextval('book_id_seq'::regclass)
name | character varying | not null
authors | character varying[] | not null
is_lent | boolean | not null default false
created_at | timestamp without time zone | not null default now()
xml_description | xml |
Indexes:
"book_pkey" PRIMARY KEY, btree (id)
YourDb\Test\Book Object
(
[fields:protected] => Array
(
[id] => 1
[name] => Hyperion
[authors] => Array
(
[0] => Dan Simmons
)
[is_lent] =>
[created_at] => DateTime Object
(
[date] => 2012-03-08 12:52:22
[timezone_type] => 3
[timezone] => Europe/Berlin
)
[xml_description] => <book_description>This is a really nice SF book.</book_description>
)
[status:protected] => 1
)
<?php
// ...
$book = $database
->getConnection()
->getMapFor('YourDb\Test\Book')
->findByPk(array('id' => 1));
print_r($book);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment