1

how are you? I have a problem with Mysql DB update using CI 4.x model update function.

$outletUpdateModel->where('id',$data['id'])->set($temp)->update()

There is no error with code. but I can not see any update on db.

Thank you for your time.

I used save() instead of update()

nice_dev
  • 17,053
  • 2
  • 21
  • 35
  • Perhaps the where clause does not match any existing rows. – Shadow Aug 08 '23 at 07:46
  • 1
    Check the return value of `$outletUpdateModel->where('id',$data['id'])->set($temp)->getCompiledUpdate()` to see if it produces a valid sql statement. Then run this statement directly on the db to see if there are rows affected. – Simon Weber Aug 08 '23 at 09:54

1 Answers1

0

This might be obvious, but make sure you have all the fields you want to update in the $allowedFields property in the your model.

<?php

namespace App\Models;

use CodeIgniter\Model;

class OutletUpdateModel extends Model
{
    protected $table      = 'tableName';
    protected $primaryKey = 'primaryKey';

    protected $allowedFields = ['field1', 'field2'];

Many times when I ran into situations when records wouldn't get stored or updated, it turned out that I had forgotten to add fields to the $allowedFields array in the model after making changes to the code or database.

Ronin-0822
  • 31
  • 6