Zend 表与主组合键的关系 - 从表中删除记录
我有三个表
//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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过以下方式解决:
$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 :)