<?php /** * Demonstrates using QuerySets to read data. */ // Include Phormium and models require __DIR__ . "/../vendor/autoload.php"; require __DIR__ . "/models/Person.php"; // Configure Phormium \Phormium\DB::configure('config.json'); // A separator for cosmetic outuput define('SEPARATOR', str_repeat('-', 50) . "\n"); /** * QuerySet is an object returned by Model::objects() which allows querying of * data in various ways. * * The simplest operation is to fetch all records from a table. */ /** * The simplest operation is to fetch all records from a table. */ $persons = Person::objects()->fetch(); echo SEPARATOR . "The person table has " . count($persons) . " records.\n"; /** * To limit the output, the results can be filtered. */ $persons = Person::objects()->filter('salary', '>', 5000)->fetch(); echo SEPARATOR . "The person table has " . count($persons) . " records with salary over 5000.\n"; /** * Note that filter() will return a new instance of QuerySet with the given * filter added to it, this allows chaining.
public static function setUpBeforeClass() { DB::configure(PHORMIUM_CONFIG_FILE); }
/** * @expectedException \Exception */ public function testFileExistsButIsADirectory() { $config = __DIR__; @DB::configure($config); }
/** * @expectedException PHPUnit_Framework_Error_Warning * @expectedExceptionMessage Attribute PDO::ATTR_ERRMODE is set to something other than PDO::ERRMODE_EXCEPTION for database "db1". This is not allowed because Phormium depends on this setting. Skipping attribute definition. */ public function testAttributesCannotChangeError() { DB::configure(["databases" => ["db1" => ["dsn" => "sqlite:tmp/test.db", "username" => "myuser", "password" => "mypass", "attributes" => [PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]]]]); // Test the warning is emitted DB::getConnection("db1"); }
public static function setUpBeforeClass() { DB::configure(PHORMIUM_CONFIG_FILE); self::$person = Person::fromArray(['name' => 'Udo Dirkschneider']); self::$person->save(); }