示例#1
0
 /**
  * Establish a new database connection
  * 
  * @param string $type
  * @param string $hostname
  * @param int $port
  * @param string $username
  * @param string $password
  * @param string $key
  * 
  * @return Connection
  */
 public function establishConnection($type, $hostname, $port, $username, $password, &$key)
 {
     $key = NULL;
     $connection = Connection::create($type, $hostname, $port, $username, $password, $key);
     $driver = $this->drivers->getDriver($type);
     // Test the connection
     if (!$driver->testConnection($connection)) {
         return null;
     }
     // Success, build and store the connection
     $store = $this->getStore();
     $store->add($connection);
     // Lock (encrypt) the credentials and return the private key
     $connection->lock();
     return $connection;
 }
示例#2
0
 /**
  * Retrieve a set of Columns representing the schema of the given table.
  * 
  * @param \DataBundle\Connection $connection
  * @param string $db
  * @param string $tableName
  * @return Column[]
  */
 public function getTableSchema(Connection $connection, $db, $tableName)
 {
     $driver = $this->drivers->getDriver($connection->getType());
     $columns = array();
     foreach ($driver->getSchema($connection, $db, $tableName) as $column) {
         $columnModel = $this->modelForColumn($column);
         $columns[] = $columnModel;
     }
     return $columns;
 }