Exemple #1
0
<?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.
Exemple #2
0
 public static function setUpBeforeClass()
 {
     DB::configure(PHORMIUM_CONFIG_FILE);
 }
Exemple #3
0
 /**
  * @expectedException \Exception
  */
 public function testFileExistsButIsADirectory()
 {
     $config = __DIR__;
     @DB::configure($config);
 }
Exemple #4
0
 /**
  * @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();
 }