info('Mariadb Remove Database...'); // getting root password $password = $this->secret('Enter root password'); // connect database try { $mysqli = new \mysqli('127.0.0.1', 'root', $password); } catch(\ErrorException $exception) { $this->error('Failed! '.$exception->getMessage()); exit(); } $database = $this->argument('database'); // check for user of database $result = $mysqli->query("SELECT User FROM mysql.db WHERE Db = '$database'"); while ($row = $result->fetch_assoc()) { // get user from row $user = $row['User']; // remove if exists $mysqli->query("DROP USER IF EXISTS $user@localhost"); $mysqli->query("DROP USER IS EXISTS $user@'%'"); } // drop database $mysqli->query("DROP DATABASE IF EXISTS $database"); $mysqli->close(); $this->info('Success! \o/ '); } }