【问题标题】:A Database Error Occurred: You must use the "set" method to update an entry发生数据库错误:您必须使用“set”方法来更新条目
【发布时间】:2021-05-26 22:14:33
【问题描述】:

这是代码:

$this->db->where('id', $id);
return $this->db->update('contractors', ((array) $contractor));

它给了我错误A Database Error Occurred: You must use the "set" method to update an entry.

【问题讨论】:

    标签: php database api codeigniter model


    【解决方案1】:

    您的问题缺少$contractor 数组,所以我在这里可能错了,但是当我在 CI 中收到此错误时,通常是因为我没有使用键/值对正确格式化我的更新/插入数据数组。

    $contractor = array(
    "name" => "John",
    "phone" => "123-123-1234"
    );
    $this->db->where('id', $id);
    return $this->db->update('contractors', $contractor);
    

    【讨论】:

    • 好吧,我就是这么想的。但问题是我正在使用 Postman 发送 API 请求。当我使用 'echo' 打印 $contractor 详细信息时,没有打印任何内容。我对 Postman 和 PHP 比较陌生,所以它更难,哈哈
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    • 2012-12-08
    • 2021-10-30
    • 2012-11-09
    • 1970-01-01
    相关资源
    最近更新 更多