I have an install routine for a php script that basically just imports a mysql file line by line. The file just contains CREATE, DROP and ALTER statements.
My tables are InnoDB and contain foreign keys. My first time through installing, everything works fine, but if someone wants to reinstall the database. I want to be able to clear everything out without having to drop the database.
When I drop the tables and referential integrity is compromised, I get an error and the install aborts. To get around this. I am dropping all foreign keys with a statement such as this: ALTER TABLE arpEntries DROP FOREIGN KEY `arpEntries_ibfk_1`;
This works fine for a reinstall but fails if there isn't anything to drop. Is there a way that I can only execute this statement if the foreign key exists? Or can I force the table to drop?