예제 #1
0
파일: DB.php 프로젝트: Macavity/phormium
 /** Connection factory */
 private static function newConnection($name)
 {
     // Fetch database configuration
     $db = Config::getDatabase($name);
     // Establish a connection
     $pdo = new PDO($db['dsn'], $db['username'], $db['password']);
     $attributes = $db['attributes'];
     // Don't allow ATTR_ERRORMODE to be changed by the configuration,
     // because Phormium depends on errors throwing exceptions.
     if (isset($attributes[PDO::ATTR_ERRMODE]) && $attributes[PDO::ATTR_ERRMODE] !== PDO::ERRMODE_EXCEPTION) {
         trigger_error("Phormium: Attribute PDO::ATTR_ERRMODE is set to something other than " . "PDO::ERRMODE_EXCEPTION for database \"{$name}\". This is not allowed because " . "Phormium depends on this setting. Skipping attribute definition.", E_USER_WARNING);
     }
     $attributes[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
     // Apply the attributes
     foreach ($attributes as $key => $value) {
         if (!$pdo->setAttribute($key, $value)) {
             throw new \Exception("Failed setting PDO attribute \"{$key}\" to \"{$value}\" on database \"{$name}\".");
         }
     }
     return new Connection($name, $pdo);
 }
예제 #2
0
파일: Query.php 프로젝트: Macavity/phormium
 public function __construct(Meta $meta)
 {
     $database = Config::getDatabase($meta->database);
     $this->driver = $this->getDriver($database['dsn']);
     $this->meta = $meta;
 }
예제 #3
0
 public function testAttributesInteger()
 {
     $dsn = 'für immer punk';
     Config::load(["databases" => ["main" => ["dsn" => $dsn, "attributes" => [PDO::ATTR_CASE => PDO::CASE_NATURAL]]]]);
     $expected = ["dsn" => $dsn, 'username' => null, 'password' => null, "attributes" => [PDO::ATTR_CASE => PDO::CASE_NATURAL]];
     $actual = Config::getDatabase('main');
     ksort($actual);
     ksort($expected);
     $this->assertSame($expected, $actual);
 }