Search code examples
phpcodeigniter

You must use the "set" method to update A Database Error Occurred


You must use the "set" method to update an entry.Filename: modules/unfollow/controllers/unfollow.phpLine Number: 251

    // save logs
                    $this->db->insert($this->tb_logs, $logs);

                    updateLogsCounter('data_logs',$item->type,'up', $this->tb_accounts, $item->account_id); 
                    updateLogsCounter('data',$item->type.'_tmp','up', $this->tb_schedule, $item->id);
                    // set time for next schedule
                    $data_update['status'] = 5;
                    $data_update['result'] = 'Successfully';
                    $rand_time = rand(5,30);
                    $data_update['time_post'] = date('Y-m-d H:i:s', strtotime(NOW) + $item->delay + $rand_time);
                }
                $this->db->where("ids", $item->ids); 
**LINE 251-->>>**   $this->db->update($this->tb_schedule, $data_update);
            }
        }
        
    }

Solution

  • Your Query should be working fine as you can pass the data as second parameter to update() but try

    Changing this

    $this->db->where("ids", $item->ids);
    $this->db->update($this->tb_schedule, $data_update);
    

    To

    $this->db->set($data_update)->where("ids", $item->ids); 
    $this->db->update($this->tb_schedule);
    

    and go through the documentation as well