/** 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); }
public function __construct(Meta $meta) { $database = Config::getDatabase($meta->database); $this->driver = $this->getDriver($database['dsn']); $this->meta = $meta; }
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); }