Ignore MySQL foreign key constraints in PHP

前端 未结 4 1576
生来不讨喜
生来不讨喜 2021-02-19 10:17

Is there a way to override mysql foreign key constraints in a php script?

I have a query passed to mysql from php, but it fails a foreign key constraint, is there any wa

4条回答
  •  借酒劲吻你
    2021-02-19 10:57

    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;
    

提交回复
热议问题