Esempio n. 1
0
 /**
  * Create a new connection
  *
  * @param Options $options        The options for the adapter
  * @param string  $connectionName The name of the connection you want to use
  *
  * @return ConnectionInterface
  * @throws Exception\Manager
  */
 public function createConnection(Options $options, $connectionName = self::CONNECTION_DEFAULT)
 {
     if (array_key_exists($options->getDatabase(), $this->databases) === false) {
         throw Exception\Manager::unknownAdapter($options->getDatabaseName());
     }
     if (array_key_exists($connectionName, $this->connections) === false) {
         throw Exception\Manager::unknownConnection($connectionName);
     }
     // Get the class names
     $databaseClass = $this->databases[$options->getDatabase()];
     $connectionClass = $this->connections[$connectionName];
     // Create the adapter for this connection
     $database = new $databaseClass($options);
     // Return the new connection
     return new $connectionClass($database);
 }
Esempio n. 2
0
File: PDO.php Progetto: aviogram/dal
 /**
  * Get the DSN representation of the options given
  *
  * @param Options $options
  *
  * @return string
  */
 protected function getDSN(Options $options)
 {
     $extra = $options->getExtraOptions();
     $dsnParts = array();
     $dsnParts[] = "host={$options->getHost()}";
     $dsnParts[] = "port={$options->getPort()}";
     if ($options->getDatabaseName() !== null) {
         $dsnParts[] = "dbname={$options->getDatabaseName()}";
     }
     if (array_key_exists('unix_socket', $extra) === true) {
         $dsnParts[] = "unix_socket={$extra['unix_socket']}";
     }
     if (array_key_exists('charset', $extra) === true) {
         $dsnParts[] = "charset={$extra['charset']}";
     }
     return 'mysql:' . implode(';', $dsnParts);
 }