/** 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; }
/** * @expectedException \Exception * @expectedExceptionMessage Invalid attribute "FOO" specified in configuration for database "main". */ public function testAttributeNameDoesNotExist() { $dsn = 'für immer punk'; Config::load(["databases" => ["main" => ["dsn" => $dsn, "attributes" => ["FOO" => PDO::CASE_NATURAL]]]]); }