/** 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 Fucoso\ORM depends on errors throwing exceptions. if (isset($attributes[PDO::ATTR_ERRMODE]) && $attributes[PDO::ATTR_ERRMODE] !== PDO::ERRMODE_EXCEPTION) { trigger_error("Fucoso\\ORM: On connection {$name}, attribute PDO::ATTR_ERRMODE is set to something other than PDO::ERRMODE_EXCEPTION. This is not allowed because Fucoso\\ORM 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 attribute \"{$key}\" to \"{$value}\""); } } return new Connection($name, $pdo); }
public function __construct(Meta $meta) { $database = Config::getDatabase($meta->database); $this->driver = $this->getDriver($database['dsn']); $this->meta = $meta; }