From b767bd579262a87d3692d010a3647e23021b4223 Mon Sep 17 00:00:00 2001 From: Steven Jones Date: Fri, 27 May 2011 22:55:13 +0100 Subject: [PATCH] Issue #982452 by Steven Jones. Fixed DB existence checking. --- db/db.drush.inc | 14 ++++++++++++++ db/mysql/mysql_service.inc | 10 ---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/db/db.drush.inc b/db/db.drush.inc index e229dac..32927ec 100644 --- a/db/db.drush.inc +++ b/db/db.drush.inc @@ -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; + } + } } diff --git a/db/mysql/mysql_service.inc b/db/mysql/mysql_service.inc index 3034476..3508af0 100644 --- a/db/mysql/mysql_service.inc +++ b/db/mysql/mysql_service.inc @@ -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); } -- 1.7.4.1