disconnect(), there will // still be a connection to the database and you wont be able to delete it. //------------------------------------------------------------------------ //close connection for any process id using airtime database since we are about to drop the database. $sql = "SELECT pg_cancel_backend(procpid) FROM pg_stat_activity WHERE datname = 'airtime';"; $command = "echo \"$sql\" | su postgres -c psql"; @exec($command, $output); echo " * Dropping the database '".$CC_CONFIG["dsn"]["database"]."'...".PHP_EOL; //dropdb returns 1 if other sessions are using the database, otherwise returns 0 $command = "su postgres -c \"dropdb ".$CC_CONFIG["dsn"]["database"]."\""; @exec($command, $output, $dbDeleteFailed); //------------------------------------------------------------------------ // Delete DB tables // We do this if dropping the database fails above. //------------------------------------------------------------------------ if ($dbDeleteFailed) { echo " * Couldn't delete the database, so deleting all the DB tables...".PHP_EOL; AirtimeInstall::DbConnect(false); if (!PEAR::isError($CC_DBC)) { $sql = "select * from pg_tables where tableowner = 'airtime'"; $rows = $CC_DBC->GetAll($sql); if (PEAR::isError($rows)) { $rows = array(); } foreach ($rows as $row) { $tablename = $row["tablename"]; echo " * Removing database table $tablename..."; if (AirtimeInstall::DbTableExists($tablename)){ $sql = "DROP TABLE $tablename CASCADE"; AirtimeInstall::InstallQuery($sql, false); $CC_DBC->dropSequence($tablename."_id"); } echo "done.".PHP_EOL; } } } //------------------------------------------------------------------------ // Delete the user //------------------------------------------------------------------------ echo " * Deleting database user '{$CC_CONFIG['dsn']['username']}'...".PHP_EOL; $command = "echo \"DROP USER IF EXISTS {$CC_CONFIG['dsn']['username']}\" | su postgres -c psql >/dev/null 2>&1"; @exec($command, $output, $results); if ($results == 0) { echo " * User '{$CC_CONFIG['dsn']['username']}' deleted.".PHP_EOL; } else { echo " * Nothing to delete.".PHP_EOL; } //AirtimeInstall::RemoveSymlinks(); //AirtimeInstall::UninstallBinaries(); //AirtimeInstall::RemoveLogDirectories(); //AirtimeInstall::removeVirtualEnvDistributeFile(); //AirtimeIni::RemoveMonitFile(); //@unlink('/etc/cron.d/airtime-crons'); /* FINISHED AIRTIME PHP UNINSTALLER */