public function testStaticDatabase() { try { Database::getDatabase('', '', '', DriverParameter::DRIVER_PDO_SQLITE, 'sqlite::memory:'); } catch (\Exception $E) { } try { Database::getDatabase('', '', '', 0, 'Wrong'); } catch (\Exception $E) { $this->assertInstanceOf('MOC\\V\\Component\\Database\\Exception\\DatabaseException', $E); } }
/** * @param string $Username * @param string $Password * @param string $Database * @param string $Driver * @param string $Host * @param null|int $Port * * @param int $Timeout * * @return Connection * @throws \Exception */ public function setConnection($Username, $Password, $Database, $Driver, $Host, $Port, $Timeout = 5) { try { $this->Connection = Database::getDatabase($Username, $Password, $Database, $Driver, $Host, $Port, $Timeout); } catch (\Exception $E) { try { Database::getDatabase($Username, $Password, null, $Driver, $Host, $Port, $Timeout)->getSchemaManager()->createDatabase($Database); $this->Connection = Database::getDatabase($Username, $Password, $Database, $Driver, $Host, $Port, $Timeout); } catch (\Exception $E) { throw new \Exception($E->getMessage(), $E->getCode(), $E); } } return $this; }
/** * @param string $Username * @param string $Password * @param string $Database * @param int $Driver * @param string $Host * @param null $Port * * @param int $Timeout * * @return IBridgeInterface */ public static function getDoctrineDatabase($Username, $Password, $Database, $Driver, $Host, $Port = null, $Timeout = 5) { $Doctrine = new Database(new Vendor(new Doctrine2ORM())); $Doctrine->getBridgeInterface()->registerConnection(new UsernameParameter($Username), new PasswordParameter($Password), new DatabaseParameter($Database), new DriverParameter($Driver), new HostParameter($Host), new PortParameter($Port), $Timeout); return $Doctrine->getBridgeInterface(); }