Ignore MySQL foreign key constraints in PHP

You can execute that MySQL query to disable foreign keys check:

SET FOREIGN_KEY_CHECKS=0;

Don't forget to enable it when you're done:

SET FOREIGN_KEY_CHECKS=1;

I have something like this in my snippet collection:

SET @BACKUP_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS; 
SET @@FOREIGN_KEY_CHECKS=0;

-- Do stuff here

SET @@FOREIGN_KEY_CHECKS=@BACKUP_FOREIGN_KEY_CHECKS;
SET @BACKUP_FOREIGN_KEY_CHECKS=NULL;

$pdo->query('SET foreign_key_checks = 0');
//do some stuff here
$pdo->query('SET foreign_key_checks = 1');