Zend 表与主组合键的关系 - 从表中删除记录

发布于 2024-10-03 10:08:40 字数 1420 浏览 7 评论 0原文

我有三个表

//1
CREATE TABLE `client_domain` (
  `client_id` int(10) unsigned NOT NULL,
  `domain_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`client_id`,`domain_id`),
  KEY `FK_client_domains_domain` (`domain_id`),
  CONSTRAINT `FK_client_domain` FOREIGN KEY (`domain_id`) REFERENCES `domain` (`id`) ON DELETE CASCADE,
  CONSTRAINT `FK_client_domains_client` FOREIGN KEY (`client_id`) REFERENCES `client` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf-8;
//2
CREATE TABLE `client` (
  `id` int(10) unsigned NOT NULL,
  `name` varchar(50) NOT NULL,
  `notes` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf-8;
//3
CREATE TABLE `domain` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `domain_name` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `IX_domain` (`domain_name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf-8;

都工作正常,但是,当我尝试使用以下方法从 client_domain 表中删除记录时:

$del = new ClientDom(array('db' => $this->_adapter));
$where[] = $del->getAdapter()->quoteInto('client_id = ?', $client);
$where[] = $del->getAdapter()->quoteInto('domain_id = ?', $domain);
$result = $del->delete($where)->toArray(); Idelete record but with an error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'client_id' in 'where clause'...

出了什么问题...如果我“fetchAll($where)”也是同样的事情,但插入时所有工作正常。

I have three tables

//1
CREATE TABLE `client_domain` (
  `client_id` int(10) unsigned NOT NULL,
  `domain_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`client_id`,`domain_id`),
  KEY `FK_client_domains_domain` (`domain_id`),
  CONSTRAINT `FK_client_domain` FOREIGN KEY (`domain_id`) REFERENCES `domain` (`id`) ON DELETE CASCADE,
  CONSTRAINT `FK_client_domains_client` FOREIGN KEY (`client_id`) REFERENCES `client` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf-8;
//2
CREATE TABLE `client` (
  `id` int(10) unsigned NOT NULL,
  `name` varchar(50) NOT NULL,
  `notes` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf-8;
//3
CREATE TABLE `domain` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `domain_name` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `IX_domain` (`domain_name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf-8;

All work fine but, when I'm trying to delete record from client_domain table using:

$del = new ClientDom(array('db' => $this->_adapter));
$where[] = $del->getAdapter()->quoteInto('client_id = ?', $client);
$where[] = $del->getAdapter()->quoteInto('domain_id = ?', $domain);
$result = $del->delete($where)->toArray(); Idelete record but with an error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'client_id' in 'where clause'...

What is wrong... Also the same thing if I 'fetchAll($where)' but on insert all work fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽袖吟 2024-10-10 10:08:40

通过以下方式解决:
$del->删除(数组(
'client_id = ?' => $客户,
'域名 ID = ?' => $域名
));
不知道为什么,但通过 $where 它不起作用...如果有人知道为什么...请写在这里:)

Resolved via:
$del->delete(array(
'client_id = ?' => $client,
'domain_id = ?' => $domain
));
Don't know why but via $where it's not works... If some one know why... please write it here :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文