/** * Drops a database from the associated MySQL Server * @param int $database The ID of the database to drop. * @return boolean */ public function drop($database) { $db = Models\Database::findOrFail($database); $dbr = Models\DatabaseServer::findOrFail($db->db_server); DB::beginTransaction(); try { $capsule = new Capsule(); $capsule->addConnection(['driver' => 'mysql', 'host' => $dbr->host, 'port' => $dbr->port, 'database' => 'mysql', 'username' => $dbr->username, 'password' => Crypt::decrypt($dbr->password), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'options' => [\PDO::ATTR_TIMEOUT => 3]]); $capsule->setAsGlobal(); Capsule::statement('DROP USER \'' . $db->username . '\'@\'' . $db->remote . '\''); Capsule::statement('DROP DATABASE ' . $db->database); $db->delete(); DB::commit(); return true; } catch (\Exception $ex) { DB::rollback(); throw $ex; } }