Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Phinx/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1419,8 +1419,8 @@ public function hasDatabase(string $name): bool
{
$rows = $this->fetchAll(
sprintf(
'SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = \'%s\'',
$name,
'SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = %s',
$this->getConnection()->quote($name),
),
);

Expand Down
2 changes: 1 addition & 1 deletion src/Phinx/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ public function createDatabase(string $name, array $options = []): void
*/
public function hasDatabase(string $name): bool
{
$sql = sprintf("SELECT count(*) FROM pg_database WHERE datname = '%s'", $name);
$sql = sprintf('SELECT count(*) FROM pg_database WHERE datname = %s', $this->getConnection()->quote($name));
$result = $this->fetchRow($sql);

return $result['count'] > 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Phinx/Db/Adapter/SqlServerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,8 @@ public function hasDatabase(string $name): bool
/** @var array<string, mixed> $result */
$result = $this->fetchRow(
sprintf(
"SELECT count(*) as [count] FROM master.dbo.sysdatabases WHERE [name] = '%s'",
$name,
'SELECT count(*) as [count] FROM master.dbo.sysdatabases WHERE [name] = %s',
$this->getConnection()->quote($name),
),
);

Expand Down
5 changes: 5 additions & 0 deletions tests/Phinx/Db/Adapter/MysqlAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,11 @@ public function testHasDatabase()
$this->assertTrue($this->adapter->hasDatabase(MYSQL_DB_CONFIG['name']));
}

public function testHasDatabaseWithSingleQuoteInName()
{
$this->assertFalse($this->adapter->hasDatabase("fake'database'name"));
}

public function testDropDatabase()
{
$this->assertFalse($this->adapter->hasDatabase('phinx_temp_database'));
Expand Down
5 changes: 5 additions & 0 deletions tests/Phinx/Db/Adapter/PostgresAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,11 @@ public function testHasDatabase()
$this->assertTrue($this->adapter->hasDatabase(PGSQL_DB_CONFIG['name']));
}

public function testHasDatabaseWithSingleQuoteInName()
{
$this->assertFalse($this->adapter->hasDatabase("fake'database'name"));
}

public function testDropDatabase()
{
$this->assertFalse($this->adapter->hasDatabase('phinx_temp_database'));
Expand Down
5 changes: 5 additions & 0 deletions tests/Phinx/Db/Adapter/SqlServerAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,11 @@ public function testHasDatabase()
$this->assertTrue($this->adapter->hasDatabase(SQLSRV_DB_CONFIG['name']));
}

public function testHasDatabaseWithSingleQuoteInName()
{
$this->assertFalse($this->adapter->hasDatabase("fake'database'name"));
}

public function testDropDatabase()
{
$this->assertFalse($this->adapter->hasDatabase('phinx_temp_database'));
Expand Down