在PHP中忽略MySQL外键约束 [英] Ignore MySQL foreign key constraints in PHP

查看:173
本文介绍了在PHP中忽略MySQL外键约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在PHP脚本中重写mysql外键限制?



我有一个查询从PHP传递给MySQL,但它失败了一个外键约束,有没有办法解决这个问题,而不改变数据库架构?

我只是做一些测试,所以我会删除行,当我完成。

解决方案

mysql_query('SET foreign_key_checks = 0');
//在这里做一些事
mysql_query('SET foreign_key_checks = 1');


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 way to get around this without altering the db schema?

I'm just doing some testing, so I'll be removing the row when I'm done.

解决方案

mysql_query('SET foreign_key_checks = 0');
//do some stuff here
mysql_query('SET foreign_key_checks = 1');

这篇关于在PHP中忽略MySQL外键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆