Skip to content

Commit

Permalink
Remove database name requirement for MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin de Graaf committed Sep 20, 2020
1 parent f8b03db commit dafe2d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Parable PHP ORM

## 0.9.2

- MySQL no longer requires a database name to establish a connection.

## 0.9.1

- When using typed properties and trying to set a value of '0', untyping it caused it to become a string value. This would end up being seen as an 'empty' value and removed from the value set.
Expand Down
4 changes: 0 additions & 4 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ protected function createMySQLConnection(): PDO
throw new Exception('MySQL requires a host.');
}

if ($this->databaseName === null) {
throw new Exception('MySQL requires a database name.');
}

$connection = $this->createConnection(...$this->buildMySQLConnectionValues());

$connection->setAttribute(PDO::ATTR_ERRMODE, $this->errorMode);
Expand Down
9 changes: 7 additions & 2 deletions tests/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,15 @@ public function testSetTypeWithMySQLWithoutHost(): void

public function testSetTypeWithMySQLWithoutDatabase(): void
{
$this->expectExceptionMessage('MySQL requires a database name.');
$this->expectExceptionMessage('mysql:host=host;port=3306;dbname=');
$this->expectException(Exception::class);

$database = new Database();
$database = new class extends Database {
protected function createConnection(...$parameters): PDO
{
throw new Exception($parameters[0]);
}
};

$database->setType(Database::TYPE_MYSQL);
$database->setHost('host');
Expand Down

0 comments on commit dafe2d3

Please sign in to comment.