gpt4 book ai didi

php - 删除数据库cakephp中的一条记录

转载 作者:行者123 更新时间:2023-11-29 09:03:21 25 4
gpt4 key购买 nike

我有配置'prefix' => 'hq_',我创建了一个表:hq_products(pd_id, pd_price, pd_name,pd_date)

在 Controller 中,我想删除一个产品。我用过:

$productId = (int) $this->params['url']['id'];
$this->Product->deleteAll(array('Product.pd_id' => $productId));

并收到错误:

Warning (512): SQL Error: 1054: Unknown column 'Product.id' in 'field list' [CORE\cake\libs\model\datasources\dbo_source.php, line 684]

查询:

SELECT `Product`.`id` FROM `hq_products` AS `Product` WHERE `Product`.`pd_id` = 1 

我还使用了:$this->Product->delete($productId);同样的错误。

请帮助我。

最佳答案

在您的产品模型中,您需要配置$primaryKey model attribute :

class Product extends AppModel {
var $primaryKey = 'pd_id';
}

CakePHP 期望 hq_products 表中的主键为 id,但您已将其命名为 pd_id。每当您偏离 conventions 时,您都需要通知 CakePHP。 .

关于php - 删除数据库cakephp中的一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7879565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com