Commit d3d91b50 authored by Steven Jones's avatar Steven Jones Committed by anarcat

Issue #982452 by Steven Jones. Fixed DB existence checking.

parent 445e9023
......@@ -339,5 +339,19 @@ class provisionService_db_pdo extends provisionService_db {
}
}
function database_exists($name) {
$dsn = $this->dsn . ';dbname=' . $name;
try {
// Try to connect to the DB to test if it exists.
$conn = new PDO($dsn, $this->creds['user'], $this->creds['pass']);
// Free the $conn memory.
$conn = NULL;
return TRUE;
}
catch (PDOException $e) {
return FALSE;
}
}
}
......@@ -13,16 +13,6 @@ class provisionService_db_mysql extends provisionService_db_pdo {
return 3306;
}
function database_exists($name) {
// An underscore in a LIKE clause is a single character wildcard, escape it.
$name = str_replace('_', '\_', $name);
$result = $this->query("SHOW DATABASES LIKE '%s'", $name);
if ($result) {
return $result->fetchColumn(0);
}
}
function drop_database($name) {
return $this->query("DROP DATABASE `%s`", $name);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment